﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0137)http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/ -->
<HTML lang=en dir=ltr xmlns="http://www.w3.org/1999/xhtml"><HEAD 
profile=http://gmpg.org/xfn/11><TITLE>SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave</TITLE><!--
	generated in 0.797 seconds
	192318 bytes batcached for 300 seconds
-->
<META http-equiv=Content-Type content="text/html; charset=UTF-8"><LINK 
media=screen 
href="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/style.css" 
type=text/css rel=stylesheet><LINK 
title="Journey to SQL Authority with Pinal Dave RSS Feed" 
href="http://blog.sqlauthority.com/feed/" type=application/rss+xml 
rel=alternate><LINK href="http://blog.sqlauthority.com/xmlrpc.php" rel=pingback>
<META content=OzU_5xIy7EG57tYokexMnIJ2C4BXOb1OIl7AVl9SiiQ 
name=google-site-verification>
<META content=0b78e56ca9fc0db2 name=y_key>
<META content=8F6DBB52BE58D7F617791A1BE13F446A name=msvalidate.01>
<SCRIPT 
src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/remote-login.htm" 
type=text/javascript></SCRIPT>

<SCRIPT type=text/javascript>
			if ( 'function' === typeof WPRemoteLogin ) {
				document.cookie = "wordpress_test_cookie=test; path=/";
				if ( document.cookie.match( /(;|^)\s*wordpress_test_cookie\=/ ) ) {
					WPRemoteLogin();
				}
			}
		</SCRIPT>
<LINK 
title="Journey to SQL Authority with Pinal Dave » SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of&nbsp;Record Comments Feed" 
href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/feed/" 
type=application/rss+xml rel=alternate>
<SCRIPT type=text/javascript>
/* <![CDATA[ */
function addLoadEvent(func){var oldonload=window.onload;if(typeof window.onload!='function'){window.onload=func;}else{window.onload=function(){oldonload();func();}}}
/* ]]> */
</SCRIPT>
<LINK 
href="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/global.css" 
type=text/css rel=stylesheet>
<SCRIPT 
src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/comment-reply.js" 
type=text/javascript></SCRIPT>
<LINK title=RSD href="http://sqlauthority.wordpress.com/xmlrpc.php?rsd" 
type=application/rsd+xml rel=EditURI><LINK 
href="http://sqlauthority.wordpress.com/wp-includes/wlwmanifest.xml" 
type=application/wlwmanifest+xml rel=wlwmanifest><LINK 
title="Journey to SQL Authority with Pinal Dave" 
href="http://blog.sqlauthority.com/" rel=index><LINK 
title="SQL SERVER – Stored Procedure – Clean Cache and Clean&nbsp;Buffer" 
href="http://blog.sqlauthority.com/2007/03/23/sql-server-stored-procedure-clean-cache-and-clean-buffer/" 
rel=prev><LINK 
title="SQL SERVER – Fix : Error 701 There is insufficient system memory to run this&nbsp;query" 
href="http://blog.sqlauthority.com/2007/03/27/sql-server-fix-error-701-there-is-insufficient-system-memory-to-run-this-query/" 
rel=next>
<META content="MSHTML 6.00.2900.5880" name=GENERATOR><LINK 
href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/" 
rel=canonical><LINK href="http://wp.me/p2NUQ-H" rel=shortlink><LINK 
href="http://www.gravatar.com/blavatar/b05cec99e9618fa4eedafd17f02a0de9?s=16&amp;d=http://s2.wp.com/i/favicon.ico" 
type=image/x-icon rel="shortcut icon"><LINK 
href="http://www.gravatar.com/blavatar/b05cec99e9618fa4eedafd17f02a0de9?s=16&amp;d=http://s2.wp.com/i/favicon.ico" 
type=image/x-icon rel=icon><LINK 
href="http://www.gravatar.com/blavatar/08e35387c05b61340e885b1763a69d9f?s=158&amp;d=http://s0.wp.com/wp-content/themes/h4/i/webclip.png" 
rel=apple-touch-icon>
<STYLE type=text/css>DIV#likes {
	MARGIN-TOP: 15px
}
.like-button {
	BORDER-RIGHT: #eee 1px solid; PADDING-RIGHT: 6px; BORDER-TOP: #eee 1px solid; PADDING-LEFT: 6px; FONT-SIZE: 13px; PADDING-BOTTOM: 2px; BORDER-LEFT: #eee 1px solid; PADDING-TOP: 2px; BORDER-BOTTOM: #eee 1px solid; FONT-FAMILY: arial, tahoma, sans-serif
}
#wpl-likebox {
	CLEAR: left; PADDING-RIGHT: 0px! important; PADDING-LEFT: 0px! important; FONT-SIZE: 11px; MIN-HEIGHT: 30px; PADDING-BOTTOM: 10px! important; MARGIN: 10px 0px; PADDING-TOP: 5px! important; FONT-FAMILY: arial, tahoma, verdana, sans-serif! important
}
#wpl-button {
	BORDER-RIGHT: #d4d4d4 1px solid; BORDER-TOP: #d4d4d4 1px solid; BACKGROUND: url(/i/buttonbg.png) repeat-x left top; FLOAT: left; BORDER-LEFT: #d4d4d4 1px solid; MARGIN-RIGHT: 7px; BORDER-BOTTOM: #d4d4d4 1px solid; moz-border-radius: 3px; webkit-border-radius: 3px; border-radius: 3px
}
#wpl-button A {
	PADDING-RIGHT: 6px! important; PADDING-LEFT: 24px! important; FONT-SIZE: 11px! important; BACKGROUND: url(/i/likestar.png) no-repeat 6px 49.8%; FLOAT: left; PADDING-BOTTOM: 2px! important; COLOR: #666! important; LINE-HEIGHT: 130%! important; PADDING-TOP: 2px! important; TEXT-DECORATION: none! important; outline: none
}
.liked#wpl-button {
	BORDER-RIGHT: #f3e389 1px solid; BORDER-TOP: #f3e389 1px solid; BACKGROUND: #feffce; BORDER-LEFT: #f3e389 1px solid; BORDER-BOTTOM: #f3e389 1px solid
}
.liked#wpl-button A {
	COLOR: #ba871b! important
}
#wpl-likebox #wpl-count {
	MIN-HEIGHT: 25px; FLOAT: left; LINE-HEIGHT: 130%! important; PADDING-TOP: 3px
}
#wpl-likebox #wpl-avatars {
	CLEAR: left; MARGIN-TOP: 15px; OVERFLOW: hidden; LINE-HEIGHT: 130%! important; max-height: 101px
}
#wpl-likebox #wpl-avatars IMG {
	BORDER-TOP-STYLE: none! important; BORDER-RIGHT-STYLE: none! important; BORDER-LEFT-STYLE: none! important; BORDER-BOTTOM-STYLE: none! important
}
</STYLE>
<LINK href="http://sqlauthority.wordpress.com/?openidserver=1" 
rel=openid.server><LINK href="http://sqlauthority.wordpress.com/" 
rel=openid.delegate><LINK title=WordPress.com 
href="http://wordpress.com/opensearch.xml" 
type=application/opensearchdescription+xml rel=search><LINK 
title="Journey to SQL Authority with Pinal Dave" 
href="http://blog.sqlauthority.com/osd.xml" 
type=application/opensearchdescription+xml rel=search>
<STYLE type=text/css>#headerimage {
	BACKGROUND: url(http://sqlauthority.files.wordpress.com/2009/05/banner_42.jpg) no-repeat
}
</STYLE>
<LINK 
href="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/blog.sqlauthority.css" 
type=text/css rel=stylesheet></HEAD>
<BODY id=section-index>
<DIV class=clearfix id=navigation>
<DIV class=menu>
<UL>
  <LI><A title=Home href="http://blog.sqlauthority.com/">Home</A> </LI>
  <LI class="page_item page-item-185"><A title=All&nbsp;Articles 
  href="http://blog.sqlauthority.com/best_top_sql_server_blog_all_post/">All&nbsp;Articles</A> 
  </LI>
  <LI class="page_item page-item-1206"><A title="SQL Interview Q &amp;&nbsp;A" 
  href="http://blog.sqlauthority.com/sql-server-interview-questions-and-answers/">SQL 
  Interview Q &amp;&nbsp;A</A> </LI>
  <LI class="page_item page-item-8691"><A title=Contact&nbsp;Me 
  href="http://blog.sqlauthority.com/contact-me-contact-pinaldave/">Contact&nbsp;Me</A> 
  </LI>
  <LI class="page_item page-item-8701"><A title=Community&nbsp;Rules 
  href="http://blog.sqlauthority.com/community-rules/">Community&nbsp;Rules</A> 
  </LI>
  <LI class="page_item page-item-4"><A title=Resume 
  href="http://blog.sqlauthority.com/sql-server-corporate-trainer-consultant/">Resume</A> 
  </LI>
  <LI class="page_item page-item-7620"><A title=SQL&nbsp;Training 
  href="http://blog.sqlauthority.com/sql-training-sqlserver-training/">SQL&nbsp;Training</A> 
  </LI></UL></DIV></DIV><!-- end id:navigation -->
<DIV id=container>
<DIV id=header>
<H1><A title="Journey to SQL Authority with Pinal Dave" 
href="http://blog.sqlauthority.com/">Journey to SQL Authority with Pinal 
Dave</A></H1>
<H2>Notes of a SQL Server MVP and Database Administrator</H2></DIV><!-- end id:header -->
<DIV id=feedarea>
<DL>
  <DT><STRONG>Feeds:</STRONG> 
  <DD><A href="http://blog.sqlauthority.com/feed/">Posts</A> 
  <DD><A href="http://blog.sqlauthority.com/comments/feed/">Comments</A> 
</DD></DL></DIV><!-- end id:feedarea -->
<DIV id=headerimage></DIV><!-- end id:headerimage -->
<DIV id=content>
<DIV id=content-main>
<DIV 
class="post-43 post type-post hentry category-pinal-dave category-sql category-sql-authority category-sql-function category-sql-index category-sql-performance category-sql-query category-sql-scripts category-sql-server category-sql-tips-and-tricks category-t-sql category-technology" 
id=post-43>
<DIV class=posttitle>
<H2>SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last 
Inserted Identity of&nbsp;Record</H2>
<P class=post-info>March 25, 2007 by <A title="Posts by pinaldave" 
href="http://blog.sqlauthority.com/author/pinaldave/">pinaldave</A> </P></DIV>
<DIV class=entry>
<DIV class=snap_preview>
<P style="TEXT-ALIGN: justify"><STRONG>SELECT @@IDENTITY</STRONG><BR>It returns 
the last IDENTITY value produced on a connection, regardless of the table that 
produced the value, and regardless of the scope of the statement that produced 
the value.<BR>@@IDENTITY will return the last identity value entered into a 
table in your current session. While @@IDENTITY is limited to the current 
session, it is not limited to the current scope. If you have a trigger on a 
table that causes an identity to be created in another table, you will get the 
identity that was created last, even if it was the trigger that created it.</P>
<P style="TEXT-ALIGN: justify"><STRONG>SELECT SCOPE_IDENTITY()</STRONG><BR>It 
returns the last IDENTITY value produced on a connection and by a statement in 
the same scope, regardless of the table that produced the 
value.<BR>SCOPE_IDENTITY(), like @@IDENTITY, will return the last identity value 
created in the current session, but it will also limit it to your current scope 
as well. In other words, it will return the last identity value that you 
explicitly created, rather than any identity that was created by a trigger or a 
user defined function.</P>
<P style="TEXT-ALIGN: justify"><STRONG>SELECT 
IDENT_CURRENT(‘tablename’)</STRONG><BR>It returns the last IDENTITY value 
produced in a table, regardless of the connection that created the value, and 
regardless of the scope of the statement that produced the 
value.<BR>IDENT_CURRENT is not limited by scope and session; it is limited to a 
specified table. IDENT_CURRENT returns the identity value generated for a 
specific table in any session and any scope. </P>
<P style="TEXT-ALIGN: justify"><EM>To avoid the potential problems associated 
with adding a trigger later on, always use SCOPE_IDENTITY() to return the 
identity of the recently added row in your T SQL Statement or Stored 
Procedure.</EM></P>
<P style="TEXT-ALIGN: justify">Reference : <STRONG>Pinal Dave (</STRONG><A 
href="http://blog.sqlauthority.com/" 
target=_blank><STRONG>http://blog.SQLAuthority.com</STRONG></A><STRONG>)</STRONG></P>
<SCRIPT 
src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/adsense.js" 
type=text/javascript></SCRIPT>
<!--adcode-->
<DIV class=adcode style="PADDING-TOP: 5px; TEXT-ALIGN: left" align=center>
<SCRIPT type=text/javascript><!--
google_ad_client = "pub-3443918307802676";
google_ad_output = 'js';
google_feedback = "on";
google_max_num_ads = "4";
google_ad_width = 336;
google_ad_height = 280;
google_ad_format = "336x280_as";
google_image_size = "336x280";
google_ad_type = "text,flash,html";
google_ad_channel = '6761376596+6268535691+1069276222+7401333398+7453468586+2794543176';
var color_bg = 'FFFFFF';
var color_text = '000000';
var color_link = '384f83';
var color_border = 'FFFFFF';
var color_url = '384f83';
google_analytics_domain_name = 'none';
//-->
</SCRIPT>

<SCRIPT 
src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/show_ads.js" 
type=text/javascript></SCRIPT>
</DIV>
<DIV style="CLEAR: both"><BR></DIV><!--/adcode--></DIV></DIV>
<P class=postmetadata>Posted in <A title="View all posts in Pinal Dave" 
href="http://en.wordpress.com/tag/pinal-dave/" rel="category tag">Pinal 
Dave</A>, <A title="View all posts in SQL" 
href="http://en.wordpress.com/tag/sql/" rel="category tag">SQL</A>, <A 
title="View all posts in SQL Authority" 
href="http://en.wordpress.com/tag/sql-authority/" rel="category tag">SQL 
Authority</A>, <A title="View all posts in SQL Function" 
href="http://en.wordpress.com/tag/sql-function/" rel="category tag">SQL 
Function</A>, <A title="View all posts in SQL Index" 
href="http://en.wordpress.com/tag/sql-index/" rel="category tag">SQL Index</A>, 
<A title="View all posts in SQL Performance" 
href="http://en.wordpress.com/tag/sql-performance/" rel="category tag">SQL 
Performance</A>, <A title="View all posts in SQL Query" 
href="http://en.wordpress.com/tag/sql-query/" rel="category tag">SQL Query</A>, 
<A title="View all posts in SQL Scripts" 
href="http://en.wordpress.com/tag/sql-scripts/" rel="category tag">SQL 
Scripts</A>, <A title="View all posts in SQL Server" 
href="http://en.wordpress.com/tag/sql-server/" rel="category tag">SQL 
Server</A>, <A title="View all posts in SQL Tips and Tricks" 
href="http://en.wordpress.com/tag/sql-tips-and-tricks/" rel="category tag">SQL 
Tips and Tricks</A>, <A title="View all posts in T SQL" 
href="http://en.wordpress.com/tag/t-sql/" rel="category tag">T SQL</A>, <A 
title="View all posts in Technology" 
href="http://en.wordpress.com/tag/technology/" rel="category tag">Technology</A> 
| 148 Comments</P><!-- You can start editing here. -->
<H3 id=comments>148 Responses</H3>
<OL class=commentlist>
  <LI class="comment even thread-even depth-1" id=comment-4044>
  <DIV id=div-comment-4044>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-4044">June 
  26, 2007 at 2:09 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-4044", "4044", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=4044#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/ce67b8f764e09dfc42a8776754ca6425.png" 
  width=48> <CITE>rahul</CITE></DIV>
  <P>very fine Article<BR>Thanx<BR>Regards<BR>Rahul</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-odd thread-alt depth-1" id=comment-4465>
  <DIV id=div-comment-4465>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-4465">July 
  9, 2007 at 1:45 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-4465", "4465", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=4465#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/04a7b759f0ce39661ca17d64a8cb7b0c.png" 
  width=48> <CITE>raksha</CITE></DIV>
  <P>can we use scope_identity() for selecting the last inserted value in 
  different server..</P><BR style="CLEAR: both"></DIV>
  <LI 
  class="comment byuser comment-author-pinaldave bypostauthor even thread-even depth-1" 
  id=comment-4466>
  <DIV id=div-comment-4466>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-4466">July 
  9, 2007 at 1:47 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-4466", "4466", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=4466#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/48aa5a2264e8a27d802bb22ab6ccf688.png" 
  width=48> <CITE><A class=url href="http://www.sqlauthority.com/" 
  rel="external nofollow">pinaldave</A></CITE></DIV>
  <P>No.</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-odd thread-alt depth-1" id=comment-4468>
  <DIV id=div-comment-4468>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-4468">July 
  9, 2007 at 2:07 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-4468", "4468", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=4468#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/04a7b759f0ce39661ca17d64a8cb7b0c.png" 
  width=48> <CITE>raksha</CITE></DIV>
  <P>actually i hv to find out max value of one pramary key field.it will always 
  a last inserted value.</P>
  <P>so if my connection is opened for one server..then i am not able to find 
  out the last inserted value with scope_identity() for that server.</P>
  <P>so for this is there any other way .. or we have to use “select 
  MAX(ID)”</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment even depth-2" id=comment-76490>
    <DIV id=div-comment-76490>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76490">June 
    16, 2010 at 6:11 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76490", "76490", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76490#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>If it is in a different server, you need to use </P>
    <P>select max(id) as lat_id from table</P><BR 
  style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment odd alt thread-even depth-1" id=comment-4770>
  <DIV id=div-comment-4770>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-4770">July 
  12, 2007 at 8:10 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-4770", "4770", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=4770#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/4428445c4d9d4b1df3cdf1af0e27f916.png" 
  width=48> <CITE>Ramgopal.M</CITE></DIV>
  <P>Is there any way to retrieve the latest value of a field inserted in a 
  table (apart from primary key field)…….if yes plz let me know…..</P><BR 
  style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment even depth-2" id=comment-76491>
    <DIV id=div-comment-76491>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76491">June 
    16, 2010 at 6:12 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76491", "76491", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76491#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>If you have identity column, datetime with default value of getdate() or 
    a timestamp, it is easy</P><BR style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment odd alt thread-odd thread-alt depth-1" id=comment-5179>
  <DIV id=div-comment-5179>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-5179">July 
  16, 2007 at 10:08 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-5179", "5179", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=5179#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/713b77a822b4906d3e16deecad76a73f.png" 
  width=48> <CITE><A class=url href="http://www.welkresort.com/" 
  rel="external nofollow">Oskar Diaz</A></CITE></DIV>
  <P>Can i use the IDENT_CURRENT to get the last record updated? I am trying to 
  implement logging on a table with a trigger but I need to get the ID of the 
  record that was updated.</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment even depth-2" id=comment-76492>
    <DIV id=div-comment-76492>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76492">June 
    16, 2010 at 6:13 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76492", "76492", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76492#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>In a trigger you can use UPDATE(col)</P><BR 
    style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment odd alt thread-even depth-1" id=comment-6528>
  <DIV id=div-comment-6528>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-6528">August 
  2, 2007 at 2:27 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-6528", "6528", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=6528#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/ad89a732f53ecaf8c1acc71d37d94c87.png" 
  width=48> <CITE><A class=url href="http://sklep.apteka-cito.pl/" 
  rel="external nofollow">Apteka internetowa</A></CITE></DIV>
  <P>Thank you for the useful informations.</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-6529>
  <DIV id=div-comment-6529>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-6529">August 
  2, 2007 at 2:29 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-6529", "6529", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=6529#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/ad89a732f53ecaf8c1acc71d37d94c87.png" 
  width=48> <CITE><A class=url href="http://sklep.apteka-cito.pl/" 
  rel="external nofollow">Apteka internetowa</A></CITE></DIV>
  <P>Can we use scope_identity() for selecting the last inserted value in 
  different server.</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment odd alt depth-2" id=comment-76493>
    <DIV id=div-comment-76493>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76493">June 
    16, 2010 at 6:14 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76493", "76493", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76493#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>No. It is not possible</P><BR style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment even thread-even depth-1" id=comment-6877>
  <DIV id=div-comment-6877>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-6877">August 
  6, 2007 at 3:44 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-6877", "6877", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=6877#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/96242d3099523e3295ed173885db2d49.png" 
  width=48> <CITE>Ana</CITE></DIV>
  <P>hi,</P>
  <P>Is it possible to find out the list of lattest used stored procedure in sql 
  server, say for eg the list of 10 stored procedure being used in a page. </P>
  <P>Is it possible to retrieve from the sysobjects ?</P><BR 
  style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment odd alt depth-2" id=comment-76494>
    <DIV id=div-comment-76494>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76494">June 
    16, 2010 at 6:17 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76494", "76494", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76494#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>Yes using a DMV</P>
    <P>SELECT TOP 10<BR>last_execution_time ,<BR>(SELECT 
    SUBSTRING(text,statement_start_offset/2,(CASE WHEN statement_end_offset = -1 
    then LEN(CONVERT(nvarchar(max), text)) * 2 ELSE statement_end_offset end 
    -statement_start_offset)/2) FROM sys.dm_exec_sql_text(sql_handle)) AS 
    query_text<BR>FROM sys.dm_exec_query_stats<BR>ORDER BY last_execution_time 
    DESC</P><BR style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-6926>
  <DIV id=div-comment-6926>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-6926">August 
  6, 2007 at 12:47 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-6926", "6926", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=6926#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/4762731e8cac9e6f0831a9a6ff3780ca.png" 
  width=48> <CITE><A class=url href="http://www.fragdev.com/" 
  rel="external nofollow">Jacob Hume</A></CITE></DIV>
  <P>Thanks, this is a great piece of information. I’m more familiar with MySQL, 
  and having a function I’m used to using makes working with MS SQL much 
  nicer!</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-7124>
  <DIV id=div-comment-7124>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-7124">August 
  8, 2007 at 6:53 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-7124", "7124", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=7124#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/6e3e63e8e407d69d14cd6aa1e6045aa8.png" 
  width=48> <CITE>sulaiman</CITE></DIV>
  <P>I want to get the last inserted identity value of a table in a different 
  server.</P>
  <P>i want to use like :<BR>select ident_current(‘server2.db1.dbo.table’)</P>
  <P>if i give like this<BR>select ident_current(‘db1.dbo.table’)<BR>i am 
  getting the result.</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment even depth-2" id=comment-76495>
    <DIV id=div-comment-76495>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76495">June 
    16, 2010 at 6:18 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76495", "76495", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76495#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>It is not possible to get it from a different server<BR>You need to use 
    </P>
    <P>select max(col) from table</P><BR style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment odd alt thread-odd thread-alt depth-1" id=comment-10361>
  <DIV id=div-comment-10361>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-10361">August 
  30, 2007 at 9:34 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-10361", "10361", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=10361#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/903449b783845409a06a437ac988d386.png" 
  width=48> <CITE>rajuneo</CITE></DIV>
  <P>I need to retrieve identity column value from the below query: </P>
  <P>INSERT INTO table-name(col1, col2) VALUES(val1, val2); SELECT 
  SCOPE_IDENTITY()</P>
  <P>using C + MS-SQL through ODBC<BR>Please find the psuedo code that I have 
  used:</P>
  <P>hstmt = SQLAllocHandle<BR>odbc_stmt = “INSERT INTO STUDENT (NAME, DIVISION) 
  VALUES (?, ?); SELECT SCOPE_IDENTITY()”<BR>SqlPrepare(hstmt, 
  odbc_stmt)<BR>SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, 
  &amp;std_name, …<BR>SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, 
  &amp;std_division, …<BR>SQLBindCol(hstmt, 3, SQL_C_SSHORT, &amp;std_id, ….</P>
  <P>SQLExecute(hstmt)<BR>SQLFetch(hstmt)</P>
  <P>————</P>
  <P>Here ID is an identity column for the student table.</P>
  <P>I am able to insert the row. But identity column value for the inserted row 
  is not getting retrieved to std_id variable after SQLFetch. </P>
  <P>Please help me to find out the problem?</P>
  <P>thanks in advance….</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment even depth-2" id=comment-72845>
    <DIV id=div-comment-72845>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-72845">May 
    24, 2010 at 3:29 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-72845", "72845", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=72845#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/b7b4b54d6e43a8699510e00d5c01a187.png" 
    width=48> <CITE>Ashok</CITE></DIV>
    <P>@@identity will work in your case…</P><BR 
  style="CLEAR: both"></DIV></LI></UL>
  <LI 
  class="comment byuser comment-author-pinaldave bypostauthor odd alt thread-even depth-1" 
  id=comment-10389>
  <DIV id=div-comment-10389>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-10389">August 
  31, 2007 at 3:03 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-10389", "10389", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=10389#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/48aa5a2264e8a27d802bb22ab6ccf688.png" 
  width=48> <CITE><A class=url href="http://www.sqlauthority.com/" 
  rel="external nofollow">pinaldave</A></CITE></DIV>
  <P>rajuneo,</P>
  <P>Your code is not in T-SQL. I will be not able to help you out.</P>
  <P>Regards,<BR>Pinal Dave ( <A href="http://www.sqlauthority.com/" 
  rel=nofollow>http://www.sqlauthority.com/</A> )</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-12134>
  <DIV id=div-comment-12134>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-12134">September 
  11, 2007 at 1:35 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-12134", "12134", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=12134#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/86930e6b9aa9ceb911ad4caffcecacac.png" 
  width=48> <CITE><A class=url 
  href="http://www.tekbydesign.com/purchase/TekByDesign_CoalitionMarine.zip" 
  rel="external nofollow">Mestophales</A></CITE></DIV>
  <P>Awesome just what I needed – thank you</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-15167>
  <DIV id=div-comment-15167>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-15167">October 
  11, 2007 at 7:28 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-15167", "15167", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=15167#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/d0eaaf08a7a52fe5f255cdaf11e96910.png" 
  width=48> <CITE><A class=url href="http://www.msinursestaffing.com/" 
  rel="external nofollow">RTW</A></CITE></DIV>
  <P>Here is the problem, I create records using the identity number from the 
  membership. I have checked the number is the same going in the db which is MS 
  SQL 2005 however I can not retrieve records using the identity number, I have 
  tried everything in grid view.</P>
  <P>For example:</P>
  <P>I have a drop down box list all users on selection it poplulates the grid 
  view control.</P>
  <P>However the grid view control does not populate I have even tried this 
  manually pasting the identity number in but it returns no results. I am 
  missing something here.</P>
  <P>I write in VB VS2005 MS SQL 2005</P>
  <P>Can you point me in the right direction to make this work? I am 
  lost.</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment even depth-2" id=comment-76496>
    <DIV id=div-comment-76496>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76496">June 
    16, 2010 at 6:20 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76496", "76496", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76496#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>Can you post the code that you used in the VB application?</P><BR 
    style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment odd alt thread-odd thread-alt depth-1" id=comment-15780>
  <DIV id=div-comment-15780>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-15780">October 
  19, 2007 at 8:20 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-15780", "15780", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=15780#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/7ae2ea32ab58a5977837ef5433c10f47.png" 
  width=48> <CITE>mircea</CITE></DIV>
  <P>How do I get the id of the last inserted row if I don’t have an identity 
  column? Of course, @@identity returns NULL in this case.</P>
  <P>Thank you</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment even depth-2" id=comment-76497>
    <DIV id=div-comment-76497>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76497">June 
    16, 2010 at 6:21 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76497", "76497", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76497#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>If you have a datetime column with the default value of getdate() or a 
    timestamp it is possible</P><BR style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment odd alt thread-even depth-1" id=comment-16194>
  <DIV id=div-comment-16194>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-16194">October 
  23, 2007 at 2:28 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-16194", "16194", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=16194#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/903449b783845409a06a437ac988d386.png" 
  width=48> <CITE>rajuneo</CITE></DIV>
  <P>Hi all,</P>
  <P>I want to post the solution for my previous question (Index: 12). After 
  digging for a lot of time, found missing piece from the code.<BR>The key 
  function is SQLMoreResults. It should be called just before SQLFetch.<BR>The 
  main purpose of SQLMoreResults is to find out if we have more than result set. 
  We can always combine multiple queries in a single statement. In that 
  scenario, we may expect multiple result sets. So to traverse from one result 
  set to other, we require to call SQLMoreResults function. </P>
  <P>thanks, rajuneo</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-17567>
  <DIV id=div-comment-17567>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-17567">November 
  5, 2007 at 7:21 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-17567", "17567", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=17567#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/0eb2b40388153c6bd6f4f9c426a17b61.png" 
  width=48> <CITE>yogesh</CITE></DIV>
  <P>INSERT INTO (SELECT Lists.ListCode ,Lists.ListName<BR>FROM Lists)<BR>VALUES 
  (‘ListCode’,'ListName’) </P>
  <P>plz tell me this statement run!!!!!!!!!</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment odd alt depth-2" id=comment-76499>
    <DIV id=div-comment-76499>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76499">June 
    16, 2010 at 6:23 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76499", "76499", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76499#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>The correct code is</P><PRE>INSERT INTO FROM Lists(ListCode ,ListName)
VALUES (‘ListCode’,'ListName’)
</PRE><BR style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment even thread-even depth-1" id=comment-19668>
  <DIV id=div-comment-19668>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-19668">November 
  14, 2007 at 5:21 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-19668", "19668", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=19668#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/f14f50f98d1386498505a296f27d846f.png" 
  width=48> <CITE>Sandeep</CITE></DIV>
  <P>Can we use bigint for identity field?</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment odd alt depth-2" id=comment-76500>
    <DIV id=div-comment-76500>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76500">June 
    16, 2010 at 6:25 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76500", "76500", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76500#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>Yes. You can use data type int, bigint, smallint, tinyint, or decimal or 
    numeric with a scale of 0</P><BR style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-20373>
  <DIV id=div-comment-20373>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-20373">November 
  16, 2007 at 9:36 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-20373", "20373", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=20373#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/98083c03aefeb03ad7b5c66707e026aa.png" 
  width=48> <CITE>c</CITE></DIV>
  <P>What can I use to get the last Identity value like @@IDENTITY but over 2 
  connections.</P>
  <P>I need to do multiple inserts and my program works with @@IDENTITY as the 
  primary key the first time the program runs.</P>
  <P>When I run it a 2nd time, I get the violation of primary key constraint and 
  the statement has terminated error.</P>
  <P>Please help!<BR>Thanks,<BR>Claudia</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-20374>
  <DIV id=div-comment-20374>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-20374">November 
  16, 2007 at 9:37 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-20374", "20374", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=20374#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/98083c03aefeb03ad7b5c66707e026aa.png" 
  width=48> <CITE>c</CITE></DIV>
  <P>Also Ident_Current(‘tableName’) does not work in SQL Server 7</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-32814>
  <DIV id=div-comment-32814>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-32814">January 
  15, 2008 at 10:21 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-32814", "32814", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=32814#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/5eb087b49cf0e4f2fa78eb3c677214c2.png" 
  width=48> <CITE>Martin</CITE></DIV>
  <P>Thanks!</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-33245>
  <DIV id=div-comment-33245>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-33245">January 
  24, 2008 at 12:38 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-33245", "33245", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=33245#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/1f72a7a3036693d85d25bbe69d243efe.png" 
  width=48> <CITE><A class=url href="http://www.ewaretechologies.com/" 
  rel="external nofollow">Najam Khan</A></CITE></DIV>
  <P>I run it but gives null value can u specify it.</P><BR 
  style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment even depth-2" id=comment-76501>
    <DIV id=div-comment-76501>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76501">June 
    16, 2010 at 6:26 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76501", "76501", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76501#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>It means data are not added to the table</P><BR 
    style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment odd alt thread-odd thread-alt depth-1" id=comment-33562>
  <DIV id=div-comment-33562>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-33562">February 
  7, 2008 at 12:53 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-33562", "33562", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=33562#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/903449b783845409a06a437ac988d386.png" 
  width=48> <CITE>rajuneo</CITE></DIV>
  <P>To 18: Yogesh:-</P>
  <P>Your statement is wrong. If you want to insert data from one table into 
  another, check this out:</P>
  <P>insert into table2(select table2.t2id, t2name) select * from table1</P><BR 
  style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment even depth-2" id=comment-76502>
    <DIV id=div-comment-76502>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76502">June 
    16, 2010 at 6:29 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76502", "76502", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76502#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>It should be</P>
    <P>insert into table2(id,name)<BR>select id,name from table1</P><BR 
    style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment odd alt thread-even depth-1" id=comment-34199>
  <DIV id=div-comment-34199>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-34199">March 
  9, 2008 at 3:50 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-34199", "34199", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=34199#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/7b3407d68dbf1d462d2ca44b4e6e1705.png" 
  width=48> <CITE>javid</CITE></DIV>
  <P>hi<BR>how to find Current row(Primary key)?</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-34441>
  <DIV id=div-comment-34441>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-34441">March 
  19, 2008 at 11:54 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-34441", "34441", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=34441#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/a6a078e93ed787fb5f2116b01c3f60bb.png" 
  width=48> <CITE><A class=url href="http://www.rprateek.blogspot.com/" 
  rel="external nofollow">Prateek</A></CITE></DIV>
  <P>Hi,<BR>I have a query it will be a great help for me.</P>
  <P>I have 3 tables</P>
  <P>table1<BR>( T1id identity (1,1) PK, Name)</P>
  <P>table 2<BR>(t2id PK, T1id, Address)</P>
  <P>table3<BR>(t3id PK,T1id,Phone)</P>
  <P>Now I need to insert data like this </P>
  <P>begin transaction<BR>—multiple rows are inserted from xml insert in table 
  1<BR>for i to 100<BR>insert into table1 values(‘adsf’)</P>
  <P>next<BR>for j to 100<BR>—Similarly multiple rows are inserted from xml 
  insert in table 2 and table 3<BR>— but I cannot get the t1ID which is in table 
  1 because it has multiple identity now after xml insert</P>
  <P>— so here in table2 and table 3 the t1ID cannot be retrieved from 
  scope_Identity()<BR>– so we need some what like array of 
  scope_Identity()<BR>next<BR>commit transaction</P>
  <P>on error<BR>rollback transaction</P>
  <P>— i think you got my point<BR>– can you please reply me at my mail address 
  provided</P>
  <P>– Thank you in advance</P>
  <P>Can you please solve this problem in sql server 2005</P><BR 
  style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment odd alt depth-2" id=comment-58800>
    <DIV id=div-comment-58800>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-58800">December 
    18, 2009 at 6:16 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-58800", "58800", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=58800#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/de8cc3dba72c17d06e82818a4e84ff5b.png" 
    width=48> <CITE>Pavan</CITE></DIV>
    <P>This is a interesting question “Prateek”.</P>
    <P>How do we track a list of SCOPE_IDENTITY() values produced by a single 
    insert statement.</P>
    <P>I had the same issue, did you got any solution for this ?</P><BR 
    style="CLEAR: both"></DIV>
    <UL class=children>
      <LI class="comment even depth-3" id=comment-58851>
      <DIV id=div-comment-58851>
      <DIV class=cmtinfo><EM>on <A title="" 
      href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-58851">December 
      20, 2009 at 7:37 pm</A> | <A class=comment-reply-link 
      onclick='return addComment.moveForm("div-comment-58851", "58851", "respond", "43")' 
      href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=58851#respond" 
      rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
      src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/2445944c24187140a40615dfbbb588dc.png" 
      width=48> <CITE><A class=url href="http://blog.sqlauthority.com/" 
      rel="external nofollow">Pinal Dave</A></CITE></DIV>
      <P>Hello Pavan,</P>
      <P>Log the SCOPE_IDENTITY() value in some table if you want to use that 
      later time. You can use trigger for this.<BR>We can provide a better 
      resolution if you can explain you requirement.</P>
      <P>Regards,<BR>Pinal Dave</P><BR style="CLEAR: both"></DIV>
      <UL class=children>
        <LI class="comment odd alt depth-4" id=comment-58868>
        <DIV id=div-comment-58868>
        <DIV class=cmtinfo><EM>on <A title="" 
        href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-58868">December 
        21, 2009 at 3:45 pm</A> | <A class=comment-reply-link 
        onclick='return addComment.moveForm("div-comment-58868", "58868", "respond", "43")' 
        href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=58868#respond" 
        rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 
        alt="" 
        src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/bc94a563b29f1d24dc50f635acf325b4.png" 
        width=48> <CITE>Pavan</CITE></DIV>
        <P>Hi Pinal,</P>
        <P>Thanks for the response. </P>
        <P>Some how I am not able to reply your resposne. A message ‘discarded’ 
        is display when I submit the comments. Is there any other way that i 
        could post you the details</P>
        <P>Regards<BR>pavan</P><BR style="CLEAR: both"></DIV></LI></UL></LI></UL>
    <LI class="comment even depth-2" id=comment-58850>
    <DIV id=div-comment-58850>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-58850">December 
    20, 2009 at 7:33 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-58850", "58850", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=58850#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/2445944c24187140a40615dfbbb588dc.png" 
    width=48> <CITE><A class=url href="http://blog.sqlauthority.com/" 
    rel="external nofollow">Pinal Dave</A></CITE></DIV>
    <P>Hello Prateek,</P>
    <P>Instead of using two saperate FOR loops, use one to insert in table1, 
    table2 and table3. This way you woud have SCOPE_IDENTITY() values for each 
    insert statement to be used in table2 and table3.</P>
    <P>Regards,<BR>Pinal Dave</P><BR style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment odd alt thread-even depth-1" id=comment-34503>
  <DIV id=div-comment-34503>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-34503">March 
  22, 2008 at 2:09 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-34503", "34503", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=34503#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/c95890179ac93b142d79edc48e85653e.png" 
  width=48> <CITE>Chetana</CITE></DIV>
  <P>good article</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-34591>
  <DIV id=div-comment-34591>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-34591">March 
  27, 2008 at 12:55 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-34591", "34591", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=34591#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/4cfc28687eb823227415e152429dede3.png" 
  width=48> <CITE>Alex Schafer</CITE></DIV>
  <P>Great article.</P>
  <P>One question though:</P>
  <P>Can we use scope_identity() for selecting the last inserted value in 
  different server?</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment odd alt depth-2" id=comment-76503>
    <DIV id=div-comment-76503>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76503">June 
    16, 2010 at 6:32 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76503", "76503", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76503#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>No. You cant use it for a different server</P><BR 
    style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment even thread-even depth-1" id=comment-35037>
  <DIV id=div-comment-35037>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-35037">April 
  14, 2008 at 9:18 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-35037", "35037", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=35037#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/cf987109560b302b86d930a8ba8ad72d.png" 
  width=48> <CITE>Vishwanath</CITE></DIV>
  <P>Dear Pinal,</P>
  <P>Firstly I would like to thank you for this wonderful site. </P>
  <P>Secondly I have a question to post.</P>
  <P>What is the syntax to alter a table to add identity property (with seed and 
  incremental values) to an already existing column in that table?</P><BR 
  style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment odd alt depth-2" id=comment-76504>
    <DIV id=div-comment-76504>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76504">June 
    16, 2010 at 6:33 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76504", "76504", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76504#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>You cant alter the existing column to have identity property<BR>The only 
    way is to create a new column with identity,drop old column and rename new 
    column to old column</P><BR style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-35038>
  <DIV id=div-comment-35038>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-35038">April 
  14, 2008 at 9:22 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-35038", "35038", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=35038#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/cf987109560b302b86d930a8ba8ad72d.png" 
  width=48> <CITE>Vishwanath</CITE></DIV>
  <P>Thanks in advance for any reply.</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-35513>
  <DIV id=div-comment-35513>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-35513">April 
  25, 2008 at 1:31 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-35513", "35513", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=35513#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/fb5894bd53ac67afd237758d487f0afa.png" 
  width=48> <CITE>Wes</CITE></DIV>
  <P>I have been running replicated servers using merge replication and SQL 2000 
  for about a year without issue. I have several sp’s that used @@Identity</P>
  <P>I upgraded to SQL 2005 last week.</P>
  <P>Guess what – those SP’s are now intermittently returning the identity of a 
  table from an associated repl trigger.</P>
  <P>Have you seen or heard of this occurring after an upgrade?</P>
  <P>Thank goodness I stumbled onto your article and was able to fix all 
  instances of @@Identity in my SP’s. (Now I have to replicate the sp’s manually 
  off-hours….)</P>
  <P>thanks<BR>Wes</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-35919>
  <DIV id=div-comment-35919>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-35919">April 
  29, 2008 at 2:44 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-35919", "35919", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=35919#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/509645a8303d66a6723bed85f5ce10cc.png" 
  width=48> <CITE>shreya</CITE></DIV>
  <P>I want to select the records from a table which are updated or added in the 
  last one month (table doesn’t have any datetime field and I can’t change the 
  structure). Is it possible to write a sql query for that?</P><BR 
  style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment odd alt depth-2" id=comment-76505>
    <DIV id=div-comment-76505>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76505">June 
    16, 2010 at 6:34 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76505", "76505", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76505#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>Without a datetime column, it is not possible</P><BR 
    style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment even thread-even depth-1" id=comment-37275>
  <DIV id=div-comment-37275>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-37275">May 
  8, 2008 at 12:42 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-37275", "37275", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=37275#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/e047a745a97ed7b0624a1f9ec030d370.png" 
  width=48> <CITE>srinivas</CITE></DIV>
  <P>to retreive the last entered record in table</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-odd thread-alt depth-1" id=comment-38024>
  <DIV id=div-comment-38024>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-38024">May 
  14, 2008 at 6:09 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-38024", "38024", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=38024#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/99c7c21157163021112231c0dfc8c09b.png" 
  width=48> <CITE>khushboo</CITE></DIV>
  <P>very informative article……..thanks a lot…..</P>
  <P>but it will be more easy to understand if examples had been put 
  here………</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-even depth-1" id=comment-38126>
  <DIV id=div-comment-38126>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-38126">May 
  15, 2008 at 8:55 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-38126", "38126", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=38126#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/88d6b9d4628035f1a21d002570e329e1.png" 
  width=48> <CITE>Vijay Anand Kannan</CITE></DIV>
  <P>Hi Viswanath,</P>
  <P>I dont think that you can add the Identity to the existing coloumn. You 
  need to drop the table and recreate with Identity. You can add a new column 
  with Identity in alter table.</P>
  <P>- Vijay Anand Kannan</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-odd thread-alt depth-1" id=comment-38286>
  <DIV id=div-comment-38286>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-38286">May 
  17, 2008 at 1:39 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-38286", "38286", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=38286#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/cdc424055bb8e67fbd2f31ed2764653f.png" 
  width=48> <CITE>Jaiveer</CITE></DIV>
  <P>Hi, Pinal,<BR>The Solution you have given seems very problem solving. I 
  will try this for sure. My problem is this that: I have an web application, 
  problem is that; when more than one user enterd data on the same time the data 
  entered wrongly i.e. user 1 data save in user2 and user 2 data saves in 
  itself(user2)</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment even depth-2" id=comment-76506>
    <DIV id=div-comment-76506>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76506">June 
    16, 2010 at 6:42 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76506", "76506", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76506#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>You need to have a Transaction for better control</P><BR 
    style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment odd alt thread-even depth-1" id=comment-38878>
  <DIV id=div-comment-38878>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-38878">May 
  30, 2008 at 2:22 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-38878", "38878", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=38878#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/a04001af817fc9eb9f5ff6132d00ea88.png" 
  width=48> <CITE>Mahee</CITE></DIV>
  <P>Iam having a real strange issue with both the @@identity and the 
  scope_identity(). The problem is running the same insert on two different 
  machines with the exact DBs and the result on machine is as expected and on 
  the other i get null values for both. unlike the examples quoted by the users 
  here, iam using a select statement instead of values list to insert.<BR>And 
  Iam using SQL 2005 w/ SP2 on both the machines. (The backward compatibility 
  levels for both are SQL server 2000 (80) if you need to know)</P>
  <P>Here is what Iam doing:</P>
  <P>INSERT INTO TEMPTABLE ( column1, column2)<BR>SELECT t1, t2 FROMNewTable 
  where t3 = ‘somevalue’;<BR>SELECT @@IDENTITY;</P>
  <P>INSERT INTO TEMPTABLE ( column1, column2)<BR>SELECT t1, t2 FROMNewTable 
  where t3 = ‘somevalue’;<BR>SELECT Scope_Identity();</P>
  <P>INSERT INTO TEMPTABLE ( column1, column2)<BR>SELECT t1, t2 FROMNewTable 
  where t3 = ‘somevalue’;<BR>SELECT Ident_Currenty(‘TEMPTABLE’);</P>
  <P>One machine gives me same value on all three statements, while the other 
  gives me null on first two and gives me a value on the third. </P>
  <P>Any insights will be appreciated.</P>
  <P>- Mahee</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment even depth-2" id=comment-76507>
    <DIV id=div-comment-76507>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76507">June 
    16, 2010 at 6:45 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76507", "76507", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76507#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>It means data are not added to the table as there is no data returned for 
    this</P>
    <P>SELECT t1, t2 FROMNewTable where t3 = ‘somevalue’;</P><BR 
    style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment odd alt thread-odd thread-alt depth-1" id=comment-39165>
  <DIV id=div-comment-39165>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-39165">June 
  12, 2008 at 3:41 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-39165", "39165", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=39165#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/5685695dfbbb1dec2650cf750bf1db15.png" 
  width=48> <CITE>scarlett</CITE></DIV>
  <P>hi </P>
  <P>Please help me out.</P>
  <P>In my stored proc, I use @ident_current of a table(Table X) as a default 
  value for my table variables (Temp Table)</P>
  <P>Now Since Im creating a Table Variable, I want one of its columns to have a 
  default value of the identity of the Table X , Now when creating this Table 
  Variable, it will not accept<BR>a variable as a default hence forcing me to 
  use Ident_Current(Table X) as the default. I know that this can produce 
  erroneous data as it applies to any session .. is there another way out? I 
  cant use @@Identity as there are 2 more Table Variables created after the 
  insertion of Table X – Hence will pick up wrong identity value ….<BR>here’s my 
  code<BR>——————————————–</P>
  <P>INSERT INTO TABLE X</P>
  <P>DECLARE A TABLE A<BR>INSERT INTO TABLE A</P>
  <P>DECLARE TABLE B<BR>INSERT INTO TABLE B</P>
  <P>DECLARE C TABLE (COL1, COL2 INT DEFAULT IDENT_CURRENT( ‘TABLE X’ 
),COL3)</P>
  <P>————————————————————</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment even depth-2" id=comment-76508>
    <DIV id=div-comment-76508>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76508">June 
    16, 2010 at 6:49 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76508", "76508", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76508#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>The code you posted is correct<BR>Did you get any problem?</P><BR 
    style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment odd alt thread-even depth-1" id=comment-41489>
  <DIV id=div-comment-41489>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-41489">August 
  8, 2008 at 7:45 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-41489", "41489", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=41489#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/269fe7c0d14ae94bb8d974ce144967ec.png" 
  width=48> <CITE><A class=url href="http://roca.waitnet.com/" 
  rel="external nofollow">Hard2Get</A></CITE></DIV>
  <P>The main problem is, I can’t get the query result from 2 different 
  connection with different table.<BR>But with the same connection/server, I can 
  get the query result.</P>
  <P>SELECT SERVER1enroll.ID<BR>FROM SERVER1enroll<BR>WHERE SERVER1enroll.ID NOT 
  IN (SELECT SERVER2enroll.ID FROM SERVER2enroll)</P>
  <P>And is there a shortcut for that SQLcode to make a faster query than 
  that.</P>
  <P>Can anyone solve that?<BR>I’m using 2 different connection, Server1 on my 
  PC, Server2 is on the other PC.</P>
  <P>I’m using VB9<BR>Can anyone share some code for development testing?</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-42640>
  <DIV id=div-comment-42640>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-42640">September 
  10, 2008 at 3:26 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-42640", "42640", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=42640#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/4ff98f0b437f9704d00ed795b795cf6d.png" 
  width=48> <CITE>suresh</CITE></DIV>
  <P>how can i add identity coloumn to existing coloum through query</P><BR 
  style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment odd alt depth-2" id=comment-76509>
    <DIV id=div-comment-76509>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76509">June 
    16, 2010 at 6:50 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76509", "76509", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76509#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>It is not possible. You need to create a new column with identity 
    property</P><BR style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment even thread-even depth-1" id=comment-42880>
  <DIV id=div-comment-42880>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-42880">September 
  17, 2008 at 3:03 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-42880", "42880", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=42880#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/c99b327a3246560187d7a4834c0197ee.png" 
  width=48> <CITE>santhosh</CITE></DIV>
  <P>i have user id table i want retrive last user id from that table<BR>i need 
  sql query for pls help me</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment odd alt depth-2" id=comment-76510>
    <DIV id=div-comment-76510>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76510">June 
    16, 2010 at 6:51 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76510", "76510", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76510#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>If the userid is in the increasing order,</P>
    <P>select max(userid) as userid from table</P><BR 
    style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-43505>
  <DIV id=div-comment-43505>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-43505">October 
  4, 2008 at 2:56 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-43505", "43505", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=43505#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/319e719c72168641986a9a635e49ca10.png" 
  width=48> <CITE>sham</CITE></DIV>
  <P>nice one .. thnk you</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-43740>
  <DIV id=div-comment-43740>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-43740">October 
  16, 2008 at 3:15 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-43740", "43740", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=43740#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/e0b63be776ce8b2e674ad5fd7ce45536.png" 
  width=48> <CITE>Ayyappan</CITE></DIV>
  <P>Can we have more than one identity column in a table?</P>
  <P>if yes, please tell me how we can do that?</P>
  <P>Thanks</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment even depth-2" id=comment-76511>
    <DIV id=div-comment-76511>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76511">June 
    16, 2010 at 6:55 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76511", "76511", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76511#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>It is not possible. Why do you need this?</P><BR 
    style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment odd alt thread-odd thread-alt depth-1" id=comment-43872>
  <DIV id=div-comment-43872>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-43872">October 
  23, 2008 at 1:06 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-43872", "43872", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=43872#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/d9b00696da93d4265c995723c5ec05a1.png" 
  width=48> <CITE>Rohit Hans</CITE></DIV>
  <P>Thanks very much. It really helped me to understand difference between 
  various options of identity.</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-even depth-1" id=comment-43968>
  <DIV id=div-comment-43968>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-43968">October 
  30, 2008 at 1:18 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-43968", "43968", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=43968#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/bc53941932e8ee06d87d4e8cf83edfd2.png" 
  width=48> <CITE><A class=url href="http://blog.joggee.com/" 
  rel="external nofollow">Joggee</A></CITE></DIV>
  <P>My problem resolve. God Bless you.<BR>I always have a first choice to 
  search here.</P>
  <P>Keep up the good work.</P>
  <P>Joggee</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-odd thread-alt depth-1" id=comment-44132>
  <DIV id=div-comment-44132>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-44132">November 
  10, 2008 at 12:24 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-44132", "44132", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=44132#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/58d38aec724f23bee5871339932f70e2.png" 
  width=48> <CITE>Bharathidasan</CITE></DIV>
  <P>Hello sir,</P>
  <P>i have 1 doubt. how can i retrieve last 10 records from a particular 
  table.</P>
  <P>pls i want answer for this</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment even depth-2" id=comment-76512>
    <DIV id=div-comment-76512>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76512">June 
    16, 2010 at 6:56 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76512", "76512", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76512#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>If you have any unique column</P>
    <P>select top 10 * from table<BR>order by unique_col desc</P><BR 
    style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment odd alt thread-even depth-1" id=comment-44261>
  <DIV id=div-comment-44261>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-44261">November 
  18, 2008 at 9:50 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-44261", "44261", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=44261#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/3f483d39c3d74f110c69d31e1fe6a828.png" 
  width=48> <CITE>nofar</CITE></DIV>
  <P>hello sir,<BR>please send me the query of fetch 10 random rows from 
  table,</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment even depth-2" id=comment-76513>
    <DIV id=div-comment-76513>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76513">June 
    16, 2010 at 6:56 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76513", "76513", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76513#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>select top 10 * from table<BR>order by newid()</P><BR 
    style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment odd alt thread-odd thread-alt depth-1" id=comment-44457>
  <DIV id=div-comment-44457>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-44457">December 
  1, 2008 at 12:05 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-44457", "44457", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=44457#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/15cf61a2e5a8c05c51b0c316ccc9de9f.png" 
  width=48> <CITE>Seema</CITE></DIV>
  <P>Good Article</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-even depth-1" id=comment-44782>
  <DIV id=div-comment-44782>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-44782">December 
  14, 2008 at 10:45 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-44782", "44782", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=44782#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/2c4ab931228ea03481008f87f489499c.png" 
  width=48> <CITE><A class=url href="http://www.interviewsworld.com/" 
  rel="external nofollow">Jai</A></CITE></DIV>
  <P>Excellent, it’s very clear and understandable article.</P>
  <P>Thanks</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-odd thread-alt depth-1" id=comment-45596>
  <DIV id=div-comment-45596>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-45596">January 
  14, 2009 at 8:43 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-45596", "45596", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=45596#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/c0faa235a49e498e400b83b4d9ed8f79.png" 
  width=48> <CITE>Helvin</CITE></DIV>
  <P>Hi,</P>
  <P>SELECT IDENT_CURRENT(’tablename’) </P>
  <P>The above selects the last record from tablename.<BR>How do i loop through 
  the last 10 records? </P>
  <P>Thanks</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment even depth-2" id=comment-76514>
    <DIV id=div-comment-76514>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76514">June 
    16, 2010 at 7:13 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76514", "76514", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76514#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>select top 10 * from tablename<BR>order by identity_col desc</P><BR 
    style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment odd alt thread-even depth-1" id=comment-45928>
  <DIV id=div-comment-45928>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-45928">January 
  23, 2009 at 1:58 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-45928", "45928", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=45928#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/ae1802d9f6bc2b72bf201f1585b72c83.png" 
  width=48> <CITE>sha</CITE></DIV>
  <P>hi, i get last id of inserted data by using SCOPE_IDENTITY() from 
table1</P>
  <P>Now my problem is how to insert the id from SCOPE_IDENTITY() to table 2</P>
  <P>any guide are welcome</P>
  <P>Thanks in advance</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-46060>
  <DIV id=div-comment-46060>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-46060">January 
  28, 2009 at 4:54 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-46060", "46060", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=46060#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/349e9e0d55eab065c12d7bfd2ba1f1af.png" 
  width=48> <CITE>João Cunha</CITE></DIV>
  <P>Nice and neat.</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-46128>
  <DIV id=div-comment-46128>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-46128">January 
  29, 2009 at 4:34 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-46128", "46128", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=46128#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/3a1df0b2ebe0a8560b66f3d50be2bc34.jpeg" 
  width=48> <CITE><A class=url href="http://jacobsebastian.blogspot.com/" 
  rel="external nofollow">Jacob Sebastian</A></CITE></DIV>
  <P>sha,</P>
  <P>A safe way to do is to assign the SCOPE_IDENTITY value to a variable after 
  the first INSERT statement. For example:</P>
  <P>DECLARE @id INT<BR>INSERT INTO firstTable(col1) SELECT 1<BR>SELECT @id = 
  SCOPE_IDENTITY()</P>
  <P>INSERT INTO secondTable(col1, id) SELECT 1,@id</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-46129>
  <DIV id=div-comment-46129>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-46129">January 
  29, 2009 at 4:38 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-46129", "46129", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=46129#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/3a1df0b2ebe0a8560b66f3d50be2bc34.jpeg" 
  width=48> <CITE><A class=url href="http://jacobsebastian.blogspot.com/" 
  rel="external nofollow">Jacob Sebastian</A></CITE></DIV>
  <P>“Helvin</P>
  <P>Hi,</P>
  <P>SELECT IDENT_CURRENT(’tablename’)</P>
  <P>The above selects the last record from tablename.<BR>How do i loop through 
  the last 10 records?</P>
  <P>Thanks”</P>
  <P>Helvin,<BR>Probably the easiest option is to select the last 10 records. 
  For example:</P>
  <P>SELECT TOP 10 col1, col2, colN<BR>FROM tablename<BR>ORDER BY 
  IdentityColumn</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-46130>
  <DIV id=div-comment-46130>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-46130">January 
  29, 2009 at 4:40 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-46130", "46130", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=46130#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/3a1df0b2ebe0a8560b66f3d50be2bc34.jpeg" 
  width=48> <CITE><A class=url href="http://jacobsebastian.blogspot.com/" 
  rel="external nofollow">Jacob Sebastian</A></CITE></DIV>
  <P>“Bharathidasan : how can i retrieve last 10 records from a particular 
  table.”</P>
  <P>Bharathidasan,<BR>Try this:<BR>SELECT TOP 10 col1, col2, colN<BR>FROM 
  tablename<BR>ORDER BY IdentityColumn</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-46131>
  <DIV id=div-comment-46131>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-46131">January 
  29, 2009 at 4:41 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-46131", "46131", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=46131#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/3a1df0b2ebe0a8560b66f3d50be2bc34.jpeg" 
  width=48> <CITE><A class=url href="http://jacobsebastian.blogspot.com/" 
  rel="external nofollow">Jacob Sebastian</A></CITE></DIV>
  <P>“Ayyappan: Can we have more than one identity column in a table?”</P>
  <P>Ayyappan,<BR>There can be only one IDENTITY column per table.</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-46132>
  <DIV id=div-comment-46132>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-46132">January 
  29, 2009 at 4:42 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-46132", "46132", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=46132#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/3a1df0b2ebe0a8560b66f3d50be2bc34.jpeg" 
  width=48> <CITE><A class=url href="http://jacobsebastian.blogspot.com/" 
  rel="external nofollow">Jacob Sebastian</A></CITE></DIV>
  <P>“suresh: how can i add identity coloumn to existing coloum through 
  query”</P>
  <P>There is no direct way to do this. However, I recently found a script that 
  helps to do this. <A 
  href="http://iomegatrix.com/Phoenix/view_blog.aspx?_id_=34" 
  rel=nofollow>http://iomegatrix.com/Phoenix/view_blog.aspx?_id_=34</A></P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-46365>
  <DIV id=div-comment-46365>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-46365">February 
  5, 2009 at 7:09 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-46365", "46365", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=46365#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/4a31afddb16411a2cf1965e71564d06e.png" 
  width=48> <CITE>Haba</CITE></DIV>
  <P>hey, nice article. thnx!</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-46584>
  <DIV id=div-comment-46584>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-46584">February 
  12, 2009 at 6:59 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-46584", "46584", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=46584#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/fe6a4eac9aedf2eb77f504a7dc34adfa.png" 
  width=48> <CITE>matt</CITE></DIV>
  <P>Penal, with so many people following your blog you should consider putting 
  some advertising on it…</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-46731>
  <DIV id=div-comment-46731>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-46731">February 
  16, 2009 at 1:51 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-46731", "46731", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=46731#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/ee1b2bf0b01a5dd9865d7ece68106801.png" 
  width=48> <CITE>sushil</CITE></DIV>
  <P>thanks, it helped me to solve a tricky problem</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-46742>
  <DIV id=div-comment-46742>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-46742">February 
  16, 2009 at 11:09 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-46742", "46742", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=46742#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/48a7b592f9a21f703129e9342aeabb02.png" 
  width=48> <CITE>Neel</CITE></DIV>
  <P>thanks, nice one.<BR>I am doing T-SQL perfomance analysis. In my case I 
  have no issue in using eigther of this, Can anyone tell me that which one 
  faster @@identity or SCOPE_IDENTITY() ??</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-46935>
  <DIV id=div-comment-46935>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-46935">February 
  20, 2009 at 3:17 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-46935", "46935", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=46935#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/86930e6b9aa9ceb911ad4caffcecacac.png" 
  width=48> <CITE><A class=url href="http://www.cgdallas.com/" 
  rel="external nofollow">Christopher Haigood</A></CITE></DIV>
  <P>You always have the answer I need – thank you!!!!</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-48652>
  <DIV id=div-comment-48652>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-48652">March 
  11, 2009 at 3:43 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-48652", "48652", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=48652#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/fbfe84754fed7e57d63faec7b30c2fed.png" 
  width=48> <CITE>harinath clavib</CITE></DIV>
  <P>Hi pinale<BR>i’m unable to access db it display’s timedout !</P>
  <P>is any problem with deadlock or network as i checked by using trace files 
  but i could not find any error msg on deadlocks.</P>
  <P>give me your valuabl sugesstion.</P>
  <P>Regards,<BR>Harinath</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-48671>
  <DIV id=div-comment-48671>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-48671">March 
  11, 2009 at 7:33 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-48671", "48671", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=48671#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/13ce88498072f19a967fac09af7a0ed8.png" 
  width=48> <CITE>Imran Mohammed</CITE></DIV>
  <P>@Harinath, </P>
  <P>Were you able to log into SQL Server and you cannot access database ?</P>
  <P>Please post exact error message.</P>
  <P>What is state of database, is it online /suspect/restoring ?</P>
  <P>Regards,<BR>IM</P><BR style="CLEAR: both"></DIV>
  <LI class="pingback odd alt thread-even depth-1" id=comment-49807>
  <DIV id=div-comment-49807>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-49807">March 
  24, 2009 at 7:02 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-49807", "49807", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=49807#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/08e35387c05b61340e885b1763a69d9f.jpeg" 
  width=48> <CITE><A class=url 
  href="http://blog.sqlauthority.com/2009/03/24/sql-server-2008-scope_identity-bug-with-multi-processor-parallel-plan-and-solution/" 
  rel="external nofollow">SQL SERVER - 2008 - SCOPE_IDENTITY Bug with Multi 
  Processor Parallel Plan and Solution Journey to SQL Authority with Pinal 
  Dave</A></CITE></DIV>
  <P>[...] used in place of @@Idnetity has bug when run in Parallel Plan. You 
  can read my explanation of @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT in 
  earlier [...]</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-50042>
  <DIV id=div-comment-50042>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-50042">March 
  26, 2009 at 8:27 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-50042", "50042", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=50042#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/61a4f1dd3777982a4fe4e939d9f88068.png" 
  width=48> <CITE>ANIL KUMAR DUBEY</CITE></DIV>
  <P>Hi,</P>
  <P>I need to know, when i should use @@identity or scope_identity() inside any 
  scope. What criteria i should keep in mind when i have to use any one of them 
  in my program.</P>
  <P>Thanks</P>
  <P>Anil kumar dubey</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment odd alt depth-2" id=comment-76516>
    <DIV id=div-comment-76516>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76516">June 
    16, 2010 at 7:18 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76516", "76516", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76516#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>Read the article again. It was already explained</P><BR 
    style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment even thread-even depth-1" id=comment-51802>
  <DIV id=div-comment-51802>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-51802">May 
  12, 2009 at 11:13 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-51802", "51802", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=51802#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/d1fec6445fb2588e5a09bc4f0979f085.png" 
  width=48> <CITE><A class=url href="http://www.whoissethlong.com/" 
  rel="external nofollow">Seth Long</A></CITE></DIV>
  <P>Great post. Exactly what I was looking for.</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-odd thread-alt depth-1" id=comment-51881>
  <DIV id=div-comment-51881>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-51881">May 
  14, 2009 at 9:53 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-51881", "51881", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=51881#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/3ff1c475163861dff7e593f47a71069d.png" 
  width=48> <CITE>Mauro</CITE></DIV>
  <P>i have used </P>
  <P>SELECT IDENT_CURRENT(dbo.ITA_STORICO_ORDINI_DISTINTA)</P>
  <P>but i have received this error </P>
  <P>Msg 4104, Level 16, State 1, Line 1<BR>The multi-part identifier 
  “dbo.ITA_STORICO_ORDINI_DISTINTA” could not be bound.</P>
  <P>??????</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment even depth-2" id=comment-76517>
    <DIV id=div-comment-76517>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76517">June 
    16, 2010 at 7:20 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76517", "76517", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76517#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>You need to use a single quote</P>
    <P>SELECT IDENT_CURRENT(‘dbo.ITA_STORICO_ORDINI_DISTINTA’)</P><BR 
    style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment odd alt thread-even depth-1" id=comment-51885>
  <DIV id=div-comment-51885>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-51885">May 
  15, 2009 at 1:38 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-51885", "51885", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=51885#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/daf8f69acf94fbe09be250bec5825934.png" 
  width=48> <CITE>CK</CITE></DIV>
  <P>SELECT CONVERT(INT, SCOPE_IDENTITY()) AS ID </P>
  <P>will return the scope identity in for OdbcCmd object. Just doing a SELECT 
  SCOPE_IDENTITY() results type cast errors if you are trying to get the ID out 
  like this</P>
  <P>ID = (int) cmd.ExecuteScalar();</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-51897>
  <DIV id=div-comment-51897>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-51897">May 
  15, 2009 at 7:56 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-51897", "51897", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=51897#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/13ce88498072f19a967fac09af7a0ed8.png" 
  width=48> <CITE>Imran Mohammed</CITE></DIV>
  <P>@Mauro</P>
  <P>Table name should be in single quotations like this,</P>
  <P>SELECT IDENT_CURRENT(‘dbo.ITA_STORICO_ORDINI_DISTINTA’)</P>
  <P>Try this, Should work.</P>
  <P>IM.</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-52303>
  <DIV id=div-comment-52303>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-52303">May 
  24, 2009 at 1:44 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-52303", "52303", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=52303#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/7794e4550eda5eeca94da92e23132b19.png" 
  width=48> <CITE>sanna</CITE></DIV>
  <P>hello ..<BR>i am trying to make a sp how looks something like this,<BR>what 
  i want is to be able to get 2tables to create a new customer. .. i dosent 
  work.. can you help me???</P>
  <P>@Namn varchar(40),<BR>@Adress varchar(50),<BR>@Postnr 
  varchar(6),<BR>@Beskrivning varchar(max),<BR>@Erbjudande 
  varchar(max),<BR>@kontaktUppgift varchar(30),<BR>@CafeId int</P>
  <P>AS<BR>BEGIN<BR>SET NOCOUNT ON;</P>
  <P>BEGIN TRAN<BR>declare @CafeId int<BR>BEGIN TRY</P>
  <P>INSERT INTO app.Cafe(Namn, Adress, PostNr, Beskrivning, 
  Erbjudande)<BR>VALUES(@Namn, @Adress,@Postnr,@Beskrivning,@Erbjudande) </P>
  <P>Insert into app.Kontakt ( kontaktUppgift , CafeID)<BR>values( 
  @kontaktUppgift,@CafeId)</P>
  <P>SET @CafeId = SCOPE_IDENTITY();</P>
  <P>COMMIT TRAN<BR>END TRY</P>
  <P>BEGIN CATCH<BR>–Återställer till innan begin tran<BR>ROLLBACK 
  TRAN<BR>RAISERROR(‘fel i överföringen.’ ,16,1)<BR>END CATCH<BR>END</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-52492>
  <DIV id=div-comment-52492>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-52492">May 
  28, 2009 at 2:09 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-52492", "52492", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=52492#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/85e4239ff9662bf8296083d98da17677.png" 
  width=48> <CITE>Alexandre Bizarro</CITE></DIV>
  <P>Tku….<BR>very smart!</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-52966>
  <DIV id=div-comment-52966>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-52966">June 
  12, 2009 at 12:40 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-52966", "52966", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=52966#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/e6d5cc4ea9a5f250f1b18dc338a0bfc8.png" 
  width=48> <CITE>Minal</CITE></DIV>
  <P>how to get identity value of last updated record?</P><BR 
  style="CLEAR: both"></DIV>
  <LI 
  class="comment byuser comment-author-gsej even thread-odd thread-alt depth-1" 
  id=comment-53235>
  <DIV id=div-comment-53235>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-53235">June 
  24, 2009 at 9:26 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-53235", "53235", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=53235#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/42248c2a06121ca04169dd2eb5ce62e8.png" 
  width=48> <CITE>gsej</CITE></DIV>
  <P>Dave, </P>
  <P>I read recently about a bug which could result in scope_identity() 
  returning the wrong value. Do you know if this issue is still outstanding, and 
  if so, should we avoid scope_identity(), or is it possible to mitigate the 
  problem in some way?</P>
  <P>The issue is described here:</P>
  <P><A 
  href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=328811" 
  rel=nofollow>https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=328811</A></P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-53308>
  <DIV id=div-comment-53308>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-53308">June 
  29, 2009 at 10:27 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-53308", "53308", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=53308#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/a98e966da11f4b742fb3ba571240d022.png" 
  width=48> <CITE>Dnyaneshwar</CITE></DIV>
  <P>@@IDENTITY is not working on SQL server 2005.<BR>Why it is not 
  working?<BR>thnks.</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-53327>
  <DIV id=div-comment-53327>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-53327">June 
  29, 2009 at 8:28 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-53327", "53327", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=53327#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/6950dd8f71086248d263a44bec6e11a0.png" 
  width=48> <CITE>Brian Tkatch</CITE></DIV>
  <P>@Dnyaneshwar</P>
  <P>What is not working about @@IDENTITY? Please give an example of what you 
  are trying, and what you expected.</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-53348>
  <DIV id=div-comment-53348>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-53348">June 
  30, 2009 at 2:41 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-53348", "53348", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=53348#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/dc6b999124525346e68797a791b01fb9.png" 
  width=48> <CITE>Nitin Gautam</CITE></DIV>
  <P>None of the above is compatible with HSQLDB.<BR>What if we want to junit 
  the MSSQL DAOs using HSQLDB in memory DB?</P>
  <P>How can we make the query compatible with both SQLServer and 
  HSQLDB??</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-54046>
  <DIV id=div-comment-54046>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-54046">July 
  24, 2009 at 11:19 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-54046", "54046", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=54046#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/c430d91a8c5f8c5514143a625565efb5.png" 
  width=48> <CITE><A class=url href="http://www.amsafe.com/" 
  rel="external nofollow">Pubudu Gayan</A></CITE></DIV>
  <P>I have problem regarding this three </P>
  <P>I have created sp for insert values in to three tables. Those three tables 
  are like steps 1st table’s primary key keeps second table and second table 
  primary key keeps the third table. Please follow following example to more 
  clarification<BR>insert Table 1 set ID1=SCOPE_IDENTITY()<BR>Cursor for table 
  2<BR>Insert table2 (foreign key ID1 ) SET ID2= SCOPE_IDENTITY()<BR>Cursor for 
  table 3<BR>Insert table3 (foreign key ID3 ) SET ID2= SCOPE_IDENTITY()<BR>END 
  CURESOR 3<BR>END CURESOR 2</P>
  <P>Can I used Scope_Identity() for this scenario or any other solutions are 
  welcome. Thanks for your advance reply.</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-55523>
  <DIV id=div-comment-55523>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-55523">September 
  2, 2009 at 6:56 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-55523", "55523", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=55523#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/f08180f3907bb0bfa53334057060807c.png" 
  width=48> <CITE>cubaman</CITE></DIV>
  <P>Prateek:<BR>Do a loop inside every insert. In that way, you’ll be able to 
  retrieve SCOPE_IDENTITY() after each insert</P>
  <P>loop:<BR>begin<BR>Insert 
  1<BR>loop:<BR>Insert2<BR>loop:<BR>begin<BR>Insert3<BR>end<BR>begin<BR>end<BR>end</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-55709>
  <DIV id=div-comment-55709>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-55709">September 
  8, 2009 at 6:44 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-55709", "55709", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=55709#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/eb0cbb24e644fdc39db264b9834d2c72.png" 
  width=48> <CITE>Rahul Bhargava</CITE></DIV>
  <P>Hello All,<BR>I wish to fetch last record from a table in sql server 2005 
  without using any group by or stored procedure is it possible</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-55810>
  <DIV id=div-comment-55810>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-55810">September 
  11, 2009 at 3:57 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-55810", "55810", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=55810#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/e09be4b870df32e377894badcfac27c5.png" 
  width=48> <CITE>Sachin Kalra</CITE></DIV>
  <P>hello</P>
  <P>would like to know the difference in terminology current session and 
  current scope. Thanks in advance.</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-55814>
  <DIV id=div-comment-55814>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-55814">September 
  11, 2009 at 7:20 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-55814", "55814", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=55814#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/e990c0b4fea080761cfdb30380327d86.jpeg" 
  width=48> <CITE><A class=url href="http://beyondrelational.com/blogs/jacob/" 
  rel="external nofollow">Jacob Sebastian</A></CITE></DIV>
  <P>@Sachin Kalra<BR>If proc A calls B and B calls C – Everything in all the 3 
  procedures are in the same session.</P>
  <P>However, the SCOPE of a piece of code in PROC C will be limited only to 
  that procedure (C). But it will be in the same session as A and B</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-55886>
  <DIV id=div-comment-55886>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-55886">September 
  15, 2009 at 5:29 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-55886", "55886", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=55886#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/d2e27ab74f3074eb4fe35f122c3248c0.png" 
  width=48> <CITE><A class=url href="http://farmplan.co.uk/" 
  rel="external nofollow">mathias</A></CITE></DIV>
  <P>Pinal,</P>
  <P>This is very good, thank you very much</P>
  <P>mathias</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-55916>
  <DIV id=div-comment-55916>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-55916">September 
  16, 2009 at 6:57 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-55916", "55916", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=55916#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/e06700d9cbb5c4ae69a47230ae84d513.png" 
  width=48> <CITE>cp</CITE></DIV>
  <P>Thanks much, Pinal!!</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-56070>
  <DIV id=div-comment-56070>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-56070">September 
  23, 2009 at 5:33 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-56070", "56070", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=56070#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/ef122dfbf1b7421b78befa1d574c0311.png" 
  width=48> <CITE><A class=url href="http://www.heavymetalpower.com/" 
  rel="external nofollow">Dan</A></CITE></DIV>
  <P>You saved me again. Your posts always provide better explanations than 
  MS</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-56462>
  <DIV id=div-comment-56462>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-56462">October 
  6, 2009 at 12:56 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-56462", "56462", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=56462#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/53cc5122f9330e87a94776c30e3bc7f8.png" 
  width=48> <CITE>Chenji</CITE></DIV>
  <P>Following SQL Query is to get the LAST INSERTED ID if the column is auto 
  increment using iBatis and SQL SERVER.</P>
  <P>– your insert statement</P>
  <P>select @@IDENTITY as value</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-56570>
  <DIV id=div-comment-56570>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-56570">October 
  10, 2009 at 2:39 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-56570", "56570", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=56570#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/6f2c47adf026141ba05f667a47af2ea3.png" 
  width=48> <CITE><A class=url href="http://www.chuckserlicious.com/" 
  rel="external nofollow">Chucksterlicious</A></CITE></DIV>
  <P>I think it’s important to note here that while @@IDENTITY and 
  SCOPE_IDENTITY() appear to work the same in the context of the same scope, 
  that only @@IDENTITY will work if you happen to be trying to reference the 
  current identity value within the same insert statement that is creating the 
  IDENTITY value. SCOPE_IDENTITY() will return a NULL value in this case. I know 
  you will ask why you would ever want to do this, but i just had a case where i 
  had to do this and SCOPE_IDENTITY() did not work.</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-57091>
  <DIV id=div-comment-57091>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-57091">October 
  28, 2009 at 9:01 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-57091", "57091", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=57091#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/e74eeaa61c8b01d0961ed1db7a20b123.png" 
  width=48> <CITE>Ieuan0928</CITE></DIV>
  <P>I’m convinced with the use of SCOPE_IDENTITY until one scenario i found out 
  that SCOPE_IDENTITY doesn’t return the desired value if Instead of Triggers is 
  implemented on the desired table.</P>
  <P>But luckily, the @@IDENTITY works with that way.</P>
  <P>However, still can’t understand the logic behind the scenario.</P>
  <P>(Scenario Notes:)</P>
  <P>INSTEAD OF TRIGGERS =&gt; checks the other tables in terms of required 
  data, then, reinserts all fields with updated data.</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-57105>
  <DIV id=div-comment-57105>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-57105">October 
  28, 2009 at 6:53 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-57105", "57105", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=57105#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/6950dd8f71086248d263a44bec6e11a0.png" 
  width=48> <CITE><A class=url href="http://tkatch.com/" 
  rel="external nofollow">Brian Tkatch</A></CITE></DIV>
  <P>@Ieuan0928</P>
  <P>Could you post the scenario please. That is odd that id did not 
  work.</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-57197>
  <DIV id=div-comment-57197>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-57197">October 
  31, 2009 at 10:17 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-57197", "57197", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=57197#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/db9ef1328c7e0261ea101abe2f08e0f8.png" 
  width=48> <CITE>Sandhya P</CITE></DIV>
  <P>Hello,</P>
  <P>I have the same question like raksha posted<BR>on July 9, 2007 at 2:07 
  am</P>
  <P>Can you please help us?</P>
  <P>Thanks and Regards,<BR>Sandhya P.</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-58096>
  <DIV id=div-comment-58096>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-58096">December 
  2, 2009 at 4:14 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-58096", "58096", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=58096#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/ab837352560bcb6a16bb5c74780976bc.png" 
  width=48> <CITE>Pradeep</CITE></DIV>
  <P>Good explanations.</P>
  <P>In one of my application SCOPE_IDENTITY() returns 1, some times. Below is 
  the Code</P>
  <P>INSERT INTO CUSTOMER(…)<BR>SELECT … FROM #temp_table</P>
  <P>SET @id = SCOPE_IDENTITY()</P>
  <P>Note: Here CUSTOMER table has a AFTER trigger.</P>
  <P>Any Guess..?</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-58873>
  <DIV id=div-comment-58873>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-58873">December 
  21, 2009 at 6:28 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-58873", "58873", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=58873#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/d7e8f79b44a9c67b3d478752e0d6e511.png" 
  width=48> <CITE>Jonathan</CITE></DIV>
  <P>Thanks for producing a nice short article that gave the answer to what I 
  was looking for.</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-59265>
  <DIV id=div-comment-59265>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-59265">January 
  2, 2010 at 5:26 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-59265", "59265", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=59265#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/6de068d59893a9209c19bbda8b35b1d3.png" 
  width=48> <CITE>Bipin</CITE></DIV>
  <P>how i know latest updated and inserted records in sql table.</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-59314>
  <DIV id=div-comment-59314>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-59314">January 
  4, 2010 at 3:19 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-59314", "59314", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=59314#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/db9ef1328c7e0261ea101abe2f08e0f8.png" 
  width=48> <CITE><A class=url href="http://www.maxpcsecure.com/" 
  rel="external nofollow">Sandhya M. Potdar</A></CITE></DIV>
  <P>Hi,</P>
  <P>SET @id = SCOPE_IDENTITY() was the solution.</P>
  <P>Thank you.</P>
  <P>Regards,<BR>Sandhya M. Potdar.</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-60041>
  <DIV id=div-comment-60041>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-60041">January 
  21, 2010 at 6:52 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-60041", "60041", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=60041#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/3c2346db8e40f517d491ada67b00fd47.png" 
  width=48> <CITE>jaspal singh</CITE></DIV>
  <P>Again good article….</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-60321>
  <DIV id=div-comment-60321>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-60321">January 
  28, 2010 at 2:24 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-60321", "60321", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=60321#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/e16c35c4055365a144086462071cf165.png" 
  width=48> <CITE>Shantanu</CITE></DIV>
  <P>SCOPE_IDENTITY() is useful when multiple user inserting data in same table 
  at same time??<BR>so that will get separate identity for each row 
  inserted.<BR>??<BR>or will get mess up</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-60328>
  <DIV id=div-comment-60328>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-60328">January 
  28, 2010 at 6:11 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-60328", "60328", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=60328#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/e990c0b4fea080761cfdb30380327d86.jpeg" 
  width=48> <CITE><A class=url href="http://beyondrelational.com/blogs/jacob" 
  rel="external nofollow">Jacob Sebastian</A></CITE></DIV>
  <P>No, SCOPE_IDENTITY does not get messed up when multiple users insert data. 
  You will get the identity value generated by your session only.</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-60354>
  <DIV id=div-comment-60354>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-60354">January 
  29, 2010 at 10:18 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-60354", "60354", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=60354#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/e16c35c4055365a144086462071cf165.png" 
  width=48> <CITE>Shantanu</CITE></DIV>
  <P>Thankx a lot</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-61492>
  <DIV id=div-comment-61492>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-61492">February 
  19, 2010 at 8:23 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-61492", "61492", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=61492#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/afd2b88d3decc3ab74ab31b492efa50e.png" 
  width=48> <CITE>Vinaykumar Srivastava</CITE></DIV>
  <P>Thanks a lot. Thearticle was very useful. Keep writing such articles as it 
  is very useful for Developer community…</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-61818>
  <DIV id=div-comment-61818>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-61818">February 
  26, 2010 at 1:12 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-61818", "61818", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=61818#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/c481dc1a1af1fdd93952dccaf2218392.png" 
  width=48> <CITE>bhachi</CITE></DIV>
  <P>Hi,</P>
  <P>I am inserting multiple record. i am getting only last record id.i need 
  latest inserted record id.<BR>SCOPE_IDENTITY() it’s givining only 1 
record.</P>
  <P>example: I inserted 3 record,i need 3 records id.</P>
  <P>Create PROCEDURE 
  [dbo].[OrganisationSelectedType_insert]<BR>(<BR>@prmOrgTypeID 
  nvarchar(50),<BR>@prmOrganisationID nvarchar(50),<BR>@prmOrganisationName 
  nvarchar(50)</P>
  <P>)<BR>AS<BR>BEGIN<BR>INSERT INTO [OrganisationTypes] 
  ([OrganisationID],[OrganisationName],[OrgTypeID])<BR>SELECT 
  @prmOrganisationID,@prmOrganisationName, data FROM [Split] (@prmOrgTypeID, 
  ‘;’)</P>
  <P>SELECT SCOPE_IDENTITY() As savedId<BR>END</P>
  <P>please help.</P>
  <P>Thanks</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-63001>
  <DIV id=div-comment-63001>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-63001">March 
  16, 2010 at 2:10 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-63001", "63001", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=63001#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/157afa47c9a0690a8fa548efeb606afe.png" 
  width=48> <CITE>Aakash</CITE></DIV>
  <P>Thanks for useful info…</P>
  <P>I needed this for a long time for improving efficiency of my 
  applications.</P>
  <P>Thanks again…</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-63924>
  <DIV id=div-comment-63924>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-63924">March 
  29, 2010 at 9:55 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-63924", "63924", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=63924#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/114c12bcb8412abc9a93573c6d1a7beb.png" 
  width=48> <CITE><A class=url href="http://www.thelasttickets.com/" 
  rel="external nofollow">john</A></CITE></DIV>
  <P>Thansk for this article.it help me to solve my problem<BR>thanks</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-64110>
  <DIV id=div-comment-64110>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-64110">March 
  31, 2010 at 3:25 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-64110", "64110", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=64110#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/ce251e2f17d0965abc6d48947ee3b0d4.png" 
  width=48> <CITE>Saravanan</CITE></DIV>
  <P>I have a table of 25 records. Client mistakenly deleted the 15th row. Can u 
  able to insert the same row with same identity? If possible how?</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-64111>
  <DIV id=div-comment-64111>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-64111">March 
  31, 2010 at 3:26 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-64111", "64111", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=64111#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/ce251e2f17d0965abc6d48947ee3b0d4.png" 
  width=48> <CITE>Saravanan</CITE></DIV>
  <P>Could U Plz help me ….</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-64155>
  <DIV id=div-comment-64155>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-64155">March 
  31, 2010 at 9:20 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-64155", "64155", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=64155#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/e990c0b4fea080761cfdb30380327d86.jpeg" 
  width=48> <CITE><A class=url href="http://beyondrelational.com/blogs/jacob" 
  rel="external nofollow">Jacob Sebastian</A></CITE></DIV>
  <P>You can do this by setting IDENTITY_INSERT to ON for the specific table. 
  Once IDENTITY_INSERT is on, you can insert a value to the IDENTITY column.</P>
  <P>Note that you need to set IDENTITY_INSERT to OFF when you are done.</P>
  <P>I have presented an example here: <A 
  href="http://beyondrelational.com/blogs/jacob/archive/2009/01/30/sql-server-how-do-i-insert-an-explicit-value-into-an-identity-column-how-do-i-update-the-value-of-an-identity-column.aspx" 
  rel=nofollow>http://beyondrelational.com/blogs/jacob/archive/2009/01/30/sql-server-how-do-i-insert-an-explicit-value-into-an-identity-column-how-do-i-update-the-value-of-an-identity-column.aspx</A></P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-65040>
  <DIV id=div-comment-65040>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-65040">April 
  12, 2010 at 5:33 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-65040", "65040", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=65040#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/5b26d61e19a42b6bb7c83b5ebb69d05e.png" 
  width=48> <CITE><A class=url href="http://pranayamr.blogspot.com/" 
  rel="external nofollow">pranay</A></CITE></DIV>
  <P>I have query like below </P>
  <P>declare @str_CustomerID int<BR>Insert into 
  IMDECONP38.[Customer].dbo.CustomerMaster<BR>( CustomerName , CustomerAddress , 
  CustomerEmail , CustomerPhone )<BR>values ( ‘werw12e’ , ‘jkj12kj’ , 
  ’3212423sdf’ , ’1212121′<BR>)</P>
  <P>select @str_CustomerID= scope_identity()</P>
  <P>after execution it returns null in my parameter</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-65068>
  <DIV id=div-comment-65068>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-65068">April 
  12, 2010 at 11:20 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-65068", "65068", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=65068#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/e990c0b4fea080761cfdb30380327d86.jpeg" 
  width=48> <CITE><A class=url href="http://beyondrelational.com/blogs/jacob" 
  rel="external nofollow">Jacob Sebastian</A></CITE></DIV>
  <P>Is there an identity column on the table?</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-67271>
  <DIV id=div-comment-67271>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-67271">April 
  28, 2010 at 5:27 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-67271", "67271", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=67271#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/ec07ee49d7cd85ff9e6e98656cdf2253.png" 
  width=48> <CITE>Habydij Raja</CITE></DIV>
  <P>May we use scope_identity() for selecting the last inserted value in 
  different server.</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-68575>
  <DIV id=div-comment-68575>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-68575">May 
  3, 2010 at 2:48 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-68575", "68575", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=68575#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/f927819e9245b9f8f0ae3b8c53fa8896.png" 
  width=48> <CITE>kapil</CITE></DIV>
  <P>hi i am kapil. I am new on this site. this is a very good article.</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-70342>
  <DIV id=div-comment-70342>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-70342">May 
  11, 2010 at 7:04 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-70342", "70342", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=70342#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/5e43614a657cfa149fc1d4b99ce4cf90.png" 
  width=48> <CITE>amol</CITE></DIV>
  <P>hi , i m amol. It is nice site to solve my problems. Thank’s</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-even depth-1" id=comment-70568>
  <DIV id=div-comment-70568>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-70568">May 
  12, 2010 at 5:17 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-70568", "70568", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=70568#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/500b6d8c6cc1d5c221d0def4c08fd000.png" 
  width=48> <CITE>psmun</CITE></DIV>
  <P>can’t we get the last updated id of a table?? thanx</P><BR 
  style="CLEAR: both"></DIV>
  <LI class="comment even thread-odd thread-alt depth-1" id=comment-70569>
  <DIV id=div-comment-70569>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-70569">May 
  12, 2010 at 5:19 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-70569", "70569", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=70569#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/500b6d8c6cc1d5c221d0def4c08fd000.png" 
  width=48> <CITE>psmun</CITE></DIV>
  <P>As we get in the insertion , can’t we get the id (primary key) of a table 
  when it’s updated??<BR>I only need to get the last updated primary key. 
  Thanx</P><BR style="CLEAR: both"></DIV>
  <UL class=children>
    <LI class="comment odd alt depth-2" id=comment-76518>
    <DIV id=div-comment-76518>
    <DIV class=cmtinfo><EM>on <A title="" 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76518">June 
    16, 2010 at 7:28 pm</A> | <A class=comment-reply-link 
    onclick='return addComment.moveForm("div-comment-76518", "76518", "respond", "43")' 
    href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76518#respond" 
    rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/030c17532b6719a7b3b41711591f30f7.png" 
    width=48> <CITE><A class=url 
    href="http://beyondrelational.com/blogs/madhivanan" 
    rel="external nofollow">Madhivanan</A></CITE></DIV>
    <P>It is possible Only if you have a timestamp column</P><BR 
    style="CLEAR: both"></DIV></LI></UL>
  <LI class="comment even thread-even depth-1" id=comment-70589>
  <DIV id=div-comment-70589>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-70589">May 
  12, 2010 at 7:37 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-70589", "70589", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=70589#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/832fa66395fd8a91891b457ab528d70c.png" 
  width=48> <CITE>Raheel</CITE></DIV>
  <P>only need to get the last updated primary key.<BR>Thanks</P>
  <P>Please answer ASAP.</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-odd thread-alt depth-1" id=comment-72858>
  <DIV id=div-comment-72858>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-72858">May 
  24, 2010 at 5:39 pm</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-72858", "72858", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=72858#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/d701dac305815d4b013d50ee156515b3.png" 
  width=48> <CITE>Manisha</CITE></DIV>
  <P>Hi Pinal,<BR>i am adding multiple rows in a table using XML. How do i get 
  @@identity of each row inserted?<BR>Please help……<BR>Also please tell me is is 
  feasible or not.</P><BR style="CLEAR: both"></DIV>
  <LI class="comment even thread-even depth-1" id=comment-76399>
  <DIV id=div-comment-76399>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76399">June 
  16, 2010 at 1:58 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-76399", "76399", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76399#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/c1af02c617c8caa995f3b558b37c8960.png" 
  width=48> <CITE>Madhu Gorthi</CITE></DIV>
  <P>In SQL server 2005 and 2008 you can use a new feature: OUTPUT clause. You 
  will get right values without mistakes.</P>
  <P>Here is the link.</P>
  <P><A href="http://technet.microsoft.com/en-us/library/ms177564.aspx" 
  rel=nofollow>http://technet.microsoft.com/en-us/library/ms177564.aspx</A></P>
  <P>This feature really helps to solve all Identity column issues along with 
  other benefits.</P><BR style="CLEAR: both"></DIV>
  <LI class="comment odd alt thread-odd thread-alt depth-1" id=comment-76711>
  <DIV id=div-comment-76711>
  <DIV class=cmtinfo><EM>on <A title="" 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-76711">June 
  18, 2010 at 11:58 am</A> | <A class=comment-reply-link 
  onclick='return addComment.moveForm("div-comment-76711", "76711", "respond", "43")' 
  href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/?replytocom=76711#respond" 
  rel=nofollow>Reply</A></EM> <IMG class="avatar avatar-48" height=48 alt="" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/98fe9b362cf35e9adfc9af6f09d7168e.png" 
  width=48> <CITE>Deepti</CITE></DIV>
  <P>Hi…Habydij Raja</P>
  <P>We cant use scope_identity() for selecting the last inserted value in 
  different server.</P><BR style="CLEAR: both"></DIV></LI></OL>
<DIV class=navigation>
<DIV class=alignleft></DIV>
<DIV class=alignright></DIV></DIV><BR>
<DIV class=post-content>
<P><SPAN class=commentsfeed><A 
href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/feed/">Comments 
RSS</A></SPAN> </P></DIV>
<DIV id=respond>
<H3>Leave a Reply</H3>
<DIV class=cancel-comment-reply><SMALL><A id=cancel-comment-reply-link 
style="DISPLAY: none" 
href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#respond" 
rel=nofollow>Click here to cancel reply.</A></SMALL> </DIV>
<FORM id=commentform action=http://blog.sqlauthority.com/wp-comments-post.php 
method=post>
<P><INPUT class=textbox id=author tabIndex=1 size=22 name=author> <LABEL 
for=author><SMALL>Name (required)</SMALL></LABEL></P>
<P><INPUT class=textbox id=email tabIndex=2 size=22 name=email> <LABEL 
for=email><SMALL>E-mail (required)</SMALL></LABEL></P>
<P><INPUT class=textbox id=url tabIndex=3 size=22 name=url> <LABEL 
for=url><SMALL>Website</SMALL></LABEL></P><!--<p><small><strong>XHTML:</strong> You can use these tags: &lt;a href=&quot;&quot; title=&quot;&quot;&gt; &lt;abbr title=&quot;&quot;&gt; &lt;acronym title=&quot;&quot;&gt; &lt;b&gt; &lt;blockquote cite=&quot;&quot;&gt; &lt;cite&gt; &lt;code&gt; &lt;pre&gt; &lt;del datetime=&quot;&quot;&gt; &lt;em&gt; &lt;i&gt; &lt;q cite=&quot;&quot;&gt; &lt;strike&gt; &lt;strong&gt; </small></p>-->
<P><TEXTAREA id=comment tabIndex=4 name=comment rows=10 cols=100></TEXTAREA></P>
<P><INPUT id=submit tabIndex=5 type=submit value="Submit Comment" name=submit> 
<INPUT id=comment_post_ID type=hidden value=43 name=comment_post_ID> <INPUT 
id=comment_parent type=hidden value=0 name=comment_parent> </P><INPUT 
type=hidden value=1280223828 name=genseq> 
<P><INPUT id=subscribe style="WIDTH: auto" tabIndex=6 type=checkbox 
value=subscribe name=subscribe> <LABEL class=subscribe-label id=subscribe-label 
for=subscribe>Notify me of follow-up comments via email.</LABEL></P>
<P><INPUT id=subscribe_blog style="WIDTH: auto" tabIndex=7 type=checkbox 
value=subscribe name=subscribe_blog> <LABEL class=subscribe-label 
id=subscribe-blog-label for=subscribe_blog>Notify me of site 
updates</LABEL></P><INPUT type=hidden value=comment-form-text4 name=sub-type> 
</FORM></DIV></DIV>
<P align=center></P></DIV><!-- end id:content-main -->
<DIV id=sidebar>
<UL>
  <LI class=sidebox>
  <DIV class=textwidget><A href="http://search.sqlauthority.com/"><IMG height=33 
  alt=Search 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/searchbox.jpg" 
  width=171 border=0></A></DIV>
  <LI class=sidebox>
  <H2>About Pinal Dave</H2>
  <DIV class=textwidget>
  <P style="TEXT-ALIGN: justify">Pinalkumar Dave is a Microsoft SQL Server MVP, 
  Mentor for <A href="http://www.solidq.in/" target=_blank>Solid Quality 
  India</A> and Microsoft Certified Trainer (MCT). He has written over 1300 
  articles on the subject on his blog at <A 
  href="http://blog.sqlauthority.com/">http://blog.sqlauthority.com/</A>. He is 
  a dynamic and proficient Principal Database Architect, Corporate Trainer and 
  Project Manager, who specializes in SQL Server Programming and has <STRONG>7 
  </STRONG>years of hands-on experience. He holds a Masters of Science degree 
  and a number of certifications, including MCTS, MCDBA and MCAD (.NET). He is 
  also Regional Mentor for PASS Asia. &nbsp;<A 
  href="https://mvp.support.microsoft.com/default.aspx/profile/pinalkumar.dave" 
  target=_blank><IMG height=73 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/mvp.jpg" 
  width=170 border=0></A> <BR><A href="http://www.linkedin.com/in/pinaldave" 
  target=_blank><IMG title="LinkedIn - Pinal Dave" height=49 
  alt="LinkedIn - Pinal Dave" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/linkedin70.jpg" 
  width=49 border=0></A> <A href="http://www.twitter.com/pinaldave" 
  target=_blank><IMG title="Twitter - Pinal Dave" height=49 
  alt="Twitter - Pinal Dave" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/twittericon70.jpg" 
  width=49 border=0></A> <A 
  href="http://www.facebook.com/group.php?gid=2542572958&amp;ref=nf" 
  target=_blank><IMG height=49 alt=facebook 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/facebook50.jpg" 
  width=49 border=0> <BR><A href="http://feedproxy.google.com/SQLAuthority" 
  target=_blank><IMG height=49 alt=Feed 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/feed-icon.png" 
  width=49 border=0> &nbsp;<A 
  href="http://www.feedburner.com/fb/a/emailverifySubmit?feedId=872428" 
  target=_blank><IMG height=49 alt=Email 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/email_icon.png" 
  width=49 border=0></A> <A href="http://www.idera.com/?s=BN_SQLAuth" 
  target=_blank><IMG height=90 alt=Idera 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/idera.png" 
  width=170 border=0></A></P></DIV>
  <LI class=sidebox>
  <H2>Blog Stats</H2>
  <UL>
    <LI>17,244,372 (17 Million+) </LI></UL>
  <LI class=sidebox>
  <H2>SQLAuthority Links</H2>
  <DIV class=textwidget>.<BR><A href="http://www.pinaldave.com/" 
  target=_blank><B>My Homepage</B></A><BR><A 
  href="http://www.pinaldave.com/sql-server-dba-resume.cfm" target=_blank><B>My 
  Resume</B></A><BR><A href="http://mssqlonline.blogspot.com/" 
  target=_blank><B>My Other Blog</B></A><BR><A href="http://www.idera.com/" 
  target=_blank><B>I prefer Idera</B></A><BR>&nbsp; &nbsp; &nbsp; 
  &nbsp;--------------------<BR><B>Top Downloads</B> <BR>&nbsp; &nbsp;<A 
  href="http://www.pinaldave.com/best-sql-server-download-list.cfm" 
  target=_blank><B>PDF Downloads</B></A><BR>&nbsp; &nbsp;<A 
  href="http://www.pinaldave.com/best-sql-server-script-download-list.cfm" 
  target=_blank><B>Script Downloads</B></A><BR><BR><B>Script Bank</B> <BR>&nbsp; 
  &nbsp;<A href="http://www.pinaldave.com/best-sql-blog-sql-server-script.cfm" 
  target=_blank><B>Favorite Scripts</B></A><BR>&nbsp; &nbsp;<A 
  href="http://www.pinaldave.com/best-sql-blog-sql-server-script1.cfm" 
  target=_blank><B>All Scripts - 1</B></A><BR>&nbsp; &nbsp;<A 
  href="http://www.pinaldave.com/best-sql-blog-sql-server-script2.cfm" 
  target=_blank><B>All Scripts - 2</B></A><BR>&nbsp; &nbsp;<A 
  href="http://www.pinaldave.com/best-sql-blog-sql-server-script3.cfm" 
  target=_blank><B>All Scripts - 3</B></A><BR><BR><B>Top Articles</B> <BR>&nbsp; 
  &nbsp;<A href="http://www.pinaldave.com/best-sql-blog-best-top-articles.cfm" 
  target=_blank><B>Best Articles </B></A><BR>&nbsp; &nbsp;<A 
  href="http://www.pinaldave.com/best-sql-blog-best-favorite-articles.cfm" 
  target=_blank><B>Favorite Articles - 1</B></A><BR>&nbsp; &nbsp;<A 
  href="http://www.pinaldave.com/best-sql-blog-best-favorite-articles2.cfm" 
  target=_blank><B>Favorite Articles - 2</B></A><BR>&nbsp; &nbsp; &nbsp; 
  &nbsp;--------------------<BR><A 
  href="http://blog.sqlauthority.com/2008/09/20/sql-server-2008-interview-questions-and-answers-complete-list-download/" 
  target=_blank><B>SQL Interview Q &amp; A</B></A><BR><A 
  href="http://blog.sqlauthority.com/2008/09/25/sql-server-guidelines-and-coding-standards/" 
  target=_blank><B>SQL Coding Standards</B></A><BR><A 
  href="http://blog.sqlauthority.com/2008/10/02/sql-server-2008-cheat-sheet-one-page-pdf-download/" 
  target=_blank><B>SQL FAQ Download</B></A><BR>&nbsp; &nbsp; &nbsp; 
  &nbsp;--------------------<BR><A href="http://jobs.sqlauthority.com/" 
  target=_blank><B>Jobs @ SQLAuthority 
  </B></A><BR><!-- AddThis Button BEGIN --><A title="Bookmark and Share" 
  href="http://www.addthis.com/bookmark.php" target=_blank><IMG height=16 
  alt="Bookmark and Share" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/button1-bm.gif" 
  width=125 border=0></A> <!-- AddThis Button END --><BR><!-- AddThis Feed Button BEGIN --><A 
  title="Subscribe using any feed reader!" 
  href="http://www.addthis.com/feed.php?pub=pinaldave&amp;h1=http%3A%2F%2Ffeeds.feedburner.com%2FSQLAuthority&amp;t1="><IMG 
  height=16 alt="AddThis Feed Button" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/button1-rss.gif" 
  width=125 border=0></A> <!-- AddThis Feed Button END --></DIV>
  <LI class=sidebox>
  <H2>Pages</H2>
  <UL>
    <LI class="page_item page-item-185"><A title=All&nbsp;Articles 
    href="http://blog.sqlauthority.com/best_top_sql_server_blog_all_post/">All&nbsp;Articles</A> 

    <LI class="page_item page-item-1206"><A title="SQL Interview Q &amp;&nbsp;A" 
    href="http://blog.sqlauthority.com/sql-server-interview-questions-and-answers/">SQL 
    Interview Q &amp;&nbsp;A</A> 
    <LI class="page_item page-item-8691"><A title=Contact&nbsp;Me 
    href="http://blog.sqlauthority.com/contact-me-contact-pinaldave/">Contact&nbsp;Me</A> 

    <UL class=children>
      <LI class="page_item page-item-144"><A title=Copyright 
      href="http://blog.sqlauthority.com/contact-me-contact-pinaldave/disclaimer-copyright/">Copyright</A> 

      <LI class="page_item page-item-5"><A title="Contact Me – Archive&nbsp;1" 
      href="http://blog.sqlauthority.com/contact-me-contact-pinaldave/contact-me-contact-pinaldave-archive-1/">Contact 
      Me – Archive&nbsp;1</A> 
      <LI class="page_item page-item-705"><A title="Contact Me – Archive&nbsp;2" 
      href="http://blog.sqlauthority.com/contact-me-contact-pinaldave/contact-me-contact-pinaldave-archive-2/">Contact 
      Me – Archive&nbsp;2</A> 
      <LI class="page_item page-item-1746"><A 
      title="Contact Me – Archive&nbsp;3" 
      href="http://blog.sqlauthority.com/contact-me-contact-pinaldave/contact-me-contact-pinaldave-archive-3/">Contact 
      Me – Archive&nbsp;3</A> 
      <LI class="page_item page-item-7859"><A 
      title="Contact Me – Archieve&nbsp;6" 
      href="http://blog.sqlauthority.com/contact-me-contact-pinaldave/contact-me-contact-pinaldave-archive-6/">Contact 
      Me – Archieve&nbsp;6</A> 
      <LI class="page_item page-item-6010"><A 
      title="Contact Me – Archive&nbsp;4" 
      href="http://blog.sqlauthority.com/contact-me-contact-pinaldave/contact-me-contact-pinaldave-archive-4/">Contact 
      Me – Archive&nbsp;4</A> 
      <LI class="page_item page-item-7608"><A 
      title="Contact Me – Archive&nbsp;5" 
      href="http://blog.sqlauthority.com/contact-me-contact-pinaldave/contact-me-contact-pinaldave-archive-5/">Contact 
      Me – Archive&nbsp;5</A> </LI></UL>
    <LI class="page_item page-item-8701"><A title=Community&nbsp;Rules 
    href="http://blog.sqlauthority.com/community-rules/">Community&nbsp;Rules</A> 

    <LI class="page_item page-item-4"><A title=Resume 
    href="http://blog.sqlauthority.com/sql-server-corporate-trainer-consultant/">Resume</A> 

    <LI class="page_item page-item-7620"><A title=SQL&nbsp;Training 
    href="http://blog.sqlauthority.com/sql-training-sqlserver-training/">SQL&nbsp;Training</A> 
    </LI></UL>
  <LI class=sidebox>
  <H2>Categories</H2>
  <UL>
    <LI class="cat-item cat-item-1"><A 
    title="View all posts filed under About Me" 
    href="http://blog.sqlauthority.com/category/about-me/">About Me</A> (81) 
    <LI class="cat-item cat-item-2185"><A 
    title="View all posts filed under Best Practices" 
    href="http://blog.sqlauthority.com/category/best-practices/">Best 
    Practices</A> (106) 
    <LI class="cat-item cat-item-50933"><A 
    title="View all posts filed under Business Intelligence" 
    href="http://blog.sqlauthority.com/category/business-intelligence/">Business 
    Intelligence</A> (30) 
    <LI class="cat-item cat-item-583452"><A 
    title="View all posts filed under Data Warehousing" 
    href="http://blog.sqlauthority.com/category/data-warehousing/">Data 
    Warehousing</A> (41) 
    <LI class="cat-item cat-item-475"><A 
    title="View all posts filed under Database" 
    href="http://blog.sqlauthority.com/category/database/">Database</A> (288) 
    <LI class="cat-item cat-item-26203"><A 
    title="View all posts filed under DBA" 
    href="http://blog.sqlauthority.com/category/dba/">DBA</A> (131) 
    <LI class="cat-item cat-item-233209"><A 
    title="View all posts filed under DMV" 
    href="http://blog.sqlauthority.com/category/dmv/">DMV</A> (4) 
    <LI class="cat-item cat-item-224713"><A 
    title="View all posts filed under MVP" 
    href="http://blog.sqlauthority.com/category/mvp/">MVP</A> (123) 
    <LI class="cat-item cat-item-322701"><A 
    title="View all posts filed under PASS" 
    href="http://blog.sqlauthority.com/category/pass/">PASS</A> (14) 
    <LI class="cat-item cat-item-1746601"><A 
    title="View all posts filed under Readers Contribution" 
    href="http://blog.sqlauthority.com/category/readers-contribution/">Readers 
    Contribution</A> (52) 
    <LI class="cat-item cat-item-116726"><A 
    title="View all posts filed under Readers Question" 
    href="http://blog.sqlauthority.com/category/readers-question/">Readers 
    Question</A> (65) 
    <LI class="cat-item cat-item-2301"><A 
    title="View all posts filed under Software Development" 
    href="http://blog.sqlauthority.com/category/software-development/">Software 
    Development</A> (69) 
    <LI class="cat-item cat-item-903877"><A 
    title="View all posts filed under SQL Add-On" 
    href="http://blog.sqlauthority.com/category/sql-add-on/">SQL Add-On</A> (99) 

    <LI class="cat-item cat-item-1256501"><A 
    title="View all posts filed under SQL Backup and Restore" 
    href="http://blog.sqlauthority.com/category/sql-backup-and-restore/">SQL 
    Backup and Restore</A> (63) 
    <LI class="cat-item cat-item-15894231"><A 
    title="View all posts filed under SQL BOL" 
    href="http://blog.sqlauthority.com/category/sql-bol/">SQL BOL</A> (11) 
    <LI class="cat-item cat-item-1230101"><A 
    title="View all posts filed under SQL Coding Standards" 
    href="http://blog.sqlauthority.com/category/sql-coding-standards/">SQL 
    Coding Standards</A> (21) 
    <LI class="cat-item cat-item-1019254"><A 
    title="View all posts filed under SQL Constraint and Keys" 
    href="http://blog.sqlauthority.com/category/sql-constraint-and-keys/">SQL 
    Constraint and Keys</A> (55) 
    <LI class="cat-item cat-item-640224"><A 
    title="View all posts filed under SQL Cursor" 
    href="http://blog.sqlauthority.com/category/sql-cursor/">SQL Cursor</A> (28) 

    <LI class="cat-item cat-item-4362777"><A 
    title="View all posts filed under SQL Data Storage" 
    href="http://blog.sqlauthority.com/category/sql-data-storage/">SQL Data 
    Storage</A> (56) 
    <LI class="cat-item cat-item-1259167"><A 
    title="View all posts filed under SQL DateTime" 
    href="http://blog.sqlauthority.com/category/sql-datetime/">SQL DateTime</A> 
    (45) 
    <LI class="cat-item cat-item-950747"><A 
    title="View all posts filed under SQL Documentation" 
    href="http://blog.sqlauthority.com/category/sql-documentation/">SQL 
    Documentation</A> (251) 
    <LI class="cat-item cat-item-1064983"><A 
    title="View all posts filed under SQL Download" 
    href="http://blog.sqlauthority.com/category/sql-download/">SQL Download</A> 
    (254) 
    <LI class="cat-item cat-item-733700"><A 
    title="View all posts filed under SQL Error Messages" 
    href="http://blog.sqlauthority.com/category/sql-error-messages/">SQL Error 
    Messages</A> (139) 
    <LI class="cat-item cat-item-640238"><A 
    title="View all posts filed under SQL Function" 
    href="http://blog.sqlauthority.com/category/sql-function/">SQL Function</A> 
    (126) 
    <LI class="cat-item cat-item-1105462"><A 
    title="View all posts filed under SQL Humor" 
    href="http://blog.sqlauthority.com/category/sql-humor/">SQL Humor</A> (26) 
    <LI class="cat-item cat-item-645318"><A 
    title="View all posts filed under SQL Index" 
    href="http://blog.sqlauthority.com/category/sql-index/">SQL Index</A> (127) 
    <LI class="cat-item cat-item-834190"><A 
    title="View all posts filed under SQL Interview Questions and Answers" 
    href="http://blog.sqlauthority.com/category/sql-interview-questions-and-answers/">SQL 
    Interview Questions and Answers</A> (61) 
    <LI class="cat-item cat-item-1158283"><A 
    title="View all posts filed under SQL Joins" 
    href="http://blog.sqlauthority.com/category/sql-joins/">SQL Joins</A> (71) 
    <LI class="cat-item cat-item-15955074"><A 
    title="View all posts filed under SQL Milestone" 
    href="http://blog.sqlauthority.com/category/sql-milestone/">SQL 
    Milestone</A> (14) 
    <LI class="cat-item cat-item-3402235"><A 
    title="View all posts filed under SQL Optimization" 
    href="http://blog.sqlauthority.com/category/sql-optimization/">SQL 
    Optimization</A> (107) 
    <LI class="cat-item cat-item-697128"><A 
    title="View all posts filed under SQL Performance" 
    href="http://blog.sqlauthority.com/category/sql-performance/">SQL 
    Performance</A> (274) 
    <LI class="cat-item cat-item-11533843"><A 
    title="View all posts filed under SQL Puzzle" 
    href="http://blog.sqlauthority.com/category/sql-puzzle/">SQL Puzzle</A> (29) 

    <LI class="cat-item cat-item-872220"><A 
    title="View all posts filed under SQL Security" 
    href="http://blog.sqlauthority.com/category/sql-security/">SQL Security</A> 
    (123) 
    <LI class="cat-item cat-item-1054423"><A 
    title="View all posts filed under SQL Server DBCC" 
    href="http://blog.sqlauthority.com/category/sql-server-dbcc/">SQL Server 
    DBCC</A> (42) 
    <LI class="cat-item cat-item-2422040"><A 
    title="View all posts filed under SQL Server Management Studio" 
    href="http://blog.sqlauthority.com/category/sql-server-management-studio/">SQL 
    Server Management Studio</A> (34) 
    <LI class="cat-item cat-item-32040460"><A 
    title="View all posts filed under SQL Spatial" 
    href="http://blog.sqlauthority.com/category/sql-spatial/">SQL Spatial</A> 
    (3) 
    <LI class="cat-item cat-item-693386"><A 
    title="View all posts filed under SQL Stored Procedure" 
    href="http://blog.sqlauthority.com/category/sql-stored-procedure/">SQL 
    Stored Procedure</A> (107) 
    <LI class="cat-item cat-item-13546747"><A 
    title="View all posts filed under SQL String" 
    href="http://blog.sqlauthority.com/category/sql-string/">SQL String</A> (22) 

    <LI class="cat-item cat-item-16954004"><A 
    title="View all posts filed under SQL System Table" 
    href="http://blog.sqlauthority.com/category/sql-system-table/">SQL System 
    Table</A> (56) 
    <LI class="cat-item cat-item-766584"><A 
    title="View all posts filed under SQL Trigger" 
    href="http://blog.sqlauthority.com/category/sql-trigger/">SQL Trigger</A> 
    (24) 
    <LI class="cat-item cat-item-9109288"><A 
    title="View all posts filed under SQL User Group" 
    href="http://blog.sqlauthority.com/category/sql-user-group/">SQL User 
    Group</A> (57) 
    <LI class="cat-item cat-item-1373611"><A 
    title="View all posts filed under SQL Utility" 
    href="http://blog.sqlauthority.com/category/sql-utility/">SQL Utility</A> 
    (134) 
    <LI class="cat-item cat-item-19794812"><A 
    title="View all posts filed under SQL White Papers" 
    href="http://blog.sqlauthority.com/category/sql-white-papers/">SQL White 
    Papers</A> (54) 
    <LI class="cat-item cat-item-9974493"><A 
    title="View all posts filed under SQL XML" 
    href="http://blog.sqlauthority.com/category/sql-xml/">SQL XML</A> (12) 
    <LI class="cat-item cat-item-1543529"><A 
    title="View all posts filed under SQLAuthority" 
    href="http://blog.sqlauthority.com/category/sqlauthority/">SQLAuthority</A> 
    (484) 
    <UL class=children>
      <LI class="cat-item cat-item-8121456"><A 
      title="View all posts filed under SQL Training" 
      href="http://blog.sqlauthority.com/category/sqlauthority/sql-training/">SQL 
      Training</A> (8) 
      <LI class="cat-item cat-item-1543522"><A 
      title="View all posts filed under SQLAuthority Author Visit" 
      href="http://blog.sqlauthority.com/category/sqlauthority/sqlauthority-author-visit/">SQLAuthority 
      Author Visit</A> (105) 
      <LI class="cat-item cat-item-1543526"><A 
      title="View all posts filed under SQLAuthority Book Review" 
      href="http://blog.sqlauthority.com/category/sqlauthority/sqlauthority-book-review/">SQLAuthority 
      Book Review</A> (21) 
      <LI class="cat-item cat-item-1543527"><A 
      title="View all posts filed under SQLAuthority News" 
      href="http://blog.sqlauthority.com/category/sqlauthority/sqlauthority-news/">SQLAuthority 
      News</A> (445) 
      <LI class="cat-item cat-item-1543528"><A 
      title="View all posts filed under SQLAuthority Website Review" 
      href="http://blog.sqlauthority.com/category/sqlauthority/sqlauthority-website-review/">SQLAuthority 
      Website Review</A> (40) </LI></UL>
    <LI class="cat-item cat-item-86759"><A 
    title="View all posts filed under SQLServer" 
    href="http://blog.sqlauthority.com/category/sqlserver/">SQLServer</A> (125) 
    <LI class="cat-item cat-item-318"><A title="View all posts filed under Tech" 
    href="http://blog.sqlauthority.com/category/tech/">Tech</A> (1106) 
    <UL class=children>
      <LI class="cat-item cat-item-1054439"><A 
      title="View all posts filed under Pinal Dave" 
      href="http://blog.sqlauthority.com/category/tech/pinal-dave/">Pinal 
      Dave</A> (1095) 
      <LI class="cat-item cat-item-1054425"><A 
      title="View all posts filed under SQL Scripts" 
      href="http://blog.sqlauthority.com/category/tech/sql-scripts/">SQL 
      Scripts</A> (634) </LI></UL>
    <LI class="cat-item cat-item-6"><A 
    title="View all posts filed under Technology" 
    href="http://blog.sqlauthority.com/category/technology/">Technology</A> 
    (1418) 
    <UL class=children>
      <LI class="cat-item cat-item-10346"><A 
      title="View all posts filed under SQL" 
      href="http://blog.sqlauthority.com/category/technology/sql/">SQL</A> 
      (1418) 
      <LI class="cat-item cat-item-648577"><A 
      title="View all posts filed under SQL Authority" 
      href="http://blog.sqlauthority.com/category/technology/sql-authority/">SQL 
      Authority</A> (1418) 
      <LI class="cat-item cat-item-311850"><A 
      title="View all posts filed under SQL Query" 
      href="http://blog.sqlauthority.com/category/technology/sql-query/">SQL 
      Query</A> (1418) 
      <LI class="cat-item cat-item-6407"><A 
      title="View all posts filed under SQL Server" 
      href="http://blog.sqlauthority.com/category/technology/sql-server/">SQL 
      Server</A> (1418) 
      <LI class="cat-item cat-item-467219"><A 
      title="View all posts filed under SQL Tips and Tricks" 
      href="http://blog.sqlauthority.com/category/technology/sql-tips-and-tricks/">SQL 
      Tips and Tricks</A> (1418) 
      <LI class="cat-item cat-item-31191"><A 
      title="View all posts filed under T SQL" 
      href="http://blog.sqlauthority.com/category/technology/t-sql/">T SQL</A> 
      (1418) </LI></UL></LI></UL>
  <LI class=sidebox>
  <H2>Top Posts</H2>
  <UL>
    <LI><A 
    href="http://blog.sqlauthority.com/2007/08/15/sql-server-insert-data-from-one-table-to-another-table-insert-into-select-select-into-table/">SQL 
    SERVER - Insert Data From One Table to Another Table - INSERT INTO SELECT - 
    SELECT INTO TABLE</A>
    <LI><A 
    href="http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/">SQL 
    SERVER - Insert Multiple Records Using One Insert Statement - Use of UNION 
    ALL</A>
    <LI><A 
    href="http://blog.sqlauthority.com/2007/06/21/sql-server-retrieve-current-date-time-in-sql-server-current_timestamp-getdate-fn-now/">SQL 
    SERVER - Retrieve Current Date Time in SQL Server CURRENT_TIMESTAMP, 
    GETDATE(), {fn NOW()}</A>
    <LI><A 
    href="http://blog.sqlauthority.com/2007/04/21/sql-server-interview-questions-and-answers-complete-list-download/">SQL 
    Server Interview Questions and Answers Complete List Download</A>
    <LI><A 
    href="http://blog.sqlauthority.com/2008/02/06/sql-server-import-csv-file-into-sql-server-using-bulk-insert-load-comma-delimited-file-into-sql-server/">SQL 
    SERVER - Import CSV File Into SQL Server Using Bulk Insert - Load Comma 
    Delimited File Into SQL Server</A>
    <LI><A 
    href="http://blog.sqlauthority.com/2007/07/07/sql-server-convert-text-to-numbers-integer-cast-and-convert/">SQL 
    SERVER - Convert Text to Numbers (Integer) - CAST and CONVERT</A>
    <LI><A 
    href="http://blog.sqlauthority.com/2009/05/21/sql-server-fix-error-provider-named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server-microsoft-sql-server-error/">SQL 
    SERVER - FIX : ERROR : (provider: Named Pipes Provider, error: 40 - Could 
    not open a connection to SQL Server) (Microsoft SQL Server, Error: )</A>
    <LI><A 
    href="http://blog.sqlauthority.com/2006/12/30/sql-server-shrinking-truncate-log-file-log-full/">SQL 
    SERVER - Shrinking Truncate Log File - Log Full</A>
    <LI><A 
    href="http://blog.sqlauthority.com/2008/09/20/sql-server-2008-interview-questions-and-answers-complete-list-download/">SQL 
    SERVER - 2008 - Interview Questions and Answers Complete List Download</A>
    <LI><A 
    href="http://blog.sqlauthority.com/2007/08/21/sql-server-2005-create-script-to-copy-database-schema-and-all-the-objects-stored-procedure-functions-triggers-tables-views-constraints-and-all-other-database-objects/">SQL 
    SERVER - 2005 - Create Script to Copy Database Schema and All The Objects - 
    Stored Procedure, Functions, Triggers, Tables, Views, Constraints and All 
    Other Database Objects</A>
    <LI><A 
    href="http://blog.sqlauthority.com/2007/02/25/sql-server-restore-database-backup-using-sql-script-t-sql/">SQL 
    SERVER - Restore Database Backup using SQL Script (T-SQL)</A>
    <LI><A 
    href="http://blog.sqlauthority.com/2007/06/26/sql-server-2005-list-all-tables-of-database/">SQL 
    SERVER - 2005 List All Tables of Database</A></LI></UL>
  <LI class=sidebox>
  <H2><LABEL for=subscribe-field>Email Subscription</LABEL></H2>
  <FORM id=subscribe-blog accept-charset=utf-8 
  action=http://subscribe.wordpress.com method=post>
  <P>Enter your email address to subscribe to this blog and receive 
  notifications of new posts by email.</P>
  <P><INPUT id=subscribe-field 
  style="PADDING-RIGHT: 2px; PADDING-LEFT: 2px; PADDING-BOTTOM: 1px; WIDTH: 95%; PADDING-TOP: 1px" 
  name=email></P><INPUT type=hidden value=subscribe name=action> <INPUT 
  type=hidden value=668536 name=blog_id> <INPUT type=hidden 
  value=http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/ 
  name=source> <INPUT type=hidden value=widget name=sub-type> <INPUT id=_wpnonce 
  type=hidden value=8f66e7d63c name=_wpnonce><INPUT type=hidden 
  value=/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/ 
  name=_wp_http_referer> 
  <P><INPUT type=submit value="Sign me up!"></P></FORM>
  <LI class=sidebox>
  <H2>Top 5 Commenters</H2>
  <DIV class=textwidget>&nbsp;&nbsp;<B>1231 - <A 
  href="http://beyondrelational.com/blogs/madhivanan/" 
  target=blank>Madhivanan</A></B> <BR>&nbsp;&nbsp;<B>433 - Imran Mohammed 
  </B><BR>&nbsp;&nbsp;287 - Brian Tkatch <BR>&nbsp;&nbsp;161- <A 
  href="http://www.sqlbiinfo.com/">Ramdas Jaya</A> <BR>&nbsp;&nbsp;128 - <A 
  href="http://weicco.spaces.live.com/" target=blank>Marko Parkkola</A> </DIV>
  <LI class=sidebox>
  <H2>Authors</H2>
  <UL>
    <LI><A href="http://blog.sqlauthority.com/author/pinaldave/"><IMG 
    class="avatar avatar-48" height=48 alt="" 
    src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/48aa5a2264e8a27d802bb22ab6ccf688.png" 
    width=48> <STRONG>pinaldave</STRONG></A> 
    <UL>
      <LI><A 
      href="http://blog.sqlauthority.com/2010/07/27/sql-server-â-computed-column-â-perisistedÂ&nbsp;andÂ&nbsp;storage/">SQL 
      SERVER – Computed Column –&nbsp;Perisisted&nbsp;and&nbsp;Storage</A> 
      <LI><A 
      href="http://blog.sqlauthority.com/2010/07/26/sql-server-fix-error-8170-insufficient-result-space-to-convert-uniqueidentifier-value-to-char/">SQL 
      SERVER – FIX: ERROR: 8170 Insufficient result space to convert 
      uniqueidentifier value&nbsp;to&nbsp;char</A> 
      <LI><A 
      href="http://blog.sqlauthority.com/2010/07/25/sqlauthority-news-last-2-day-to-win-msdn-subscription-total-2-to-win/">SQLAuthority 
      News – Last 2 Day to Win MSDN Subscription – Total 2 to&nbsp;Win</A> 
      <LI><A 
      href="http://blog.sqlauthority.com/2010/07/24/sqlauthority-news-the-story-of-the-world-spatial-data-types-july-24-2010/">SQLAuthority 
      News – The story of the world – Spatial Data types – July 
      24,&nbsp;2010</A> 
      <LI><A 
      href="http://blog.sqlauthority.com/2010/07/24/sql-server-find-queries-using-parallelism-from-cached-plan/">SQL 
      SERVER – Find Queries using Parallelism from Cached&nbsp;Plan</A> 
      <LI><A 
      href="http://blog.sqlauthority.com/2010/07/23/sqlauthority-news-guest-post-walkthrough-on-creating-wcf-data-service-odata-and-consuming-in-windows-7-mobile-application/">SQLAuthority 
      News – Guest Post – Walkthrough on Creating WCF Data Service (ODATA) and 
      Consuming in Windows 7 Mobile&nbsp;application</A> 
      <LI><A 
      href="http://blog.sqlauthority.com/2010/07/22/sqlauthority-news-solidq-journal-released-a-must-read-for-all/">SQLAuthority 
      News – SolidQ Journal Released – A Must Read for&nbsp;All</A> 
      <LI><A 
      href="http://blog.sqlauthority.com/2010/07/21/sql-server-win-usd-11899-worth-msdn-subscription-5-days-to-go/">SQL 
      SERVER – Win USD 11,899 worth MSDN Subscription 5 Days to&nbsp;go</A> 
      <LI><A 
      href="http://blog.sqlauthority.com/2010/07/20/sql-server-select-from-dual-dual-equivalent/">SQL 
      SERVER – SELECT * FROM dual – Dual&nbsp;Equivalent</A> 
      <LI><A 
      href="http://blog.sqlauthority.com/2010/07/19/sql-server-identifying-statistics-used-by-query/">SQL 
      SERVER – Identifying Statistics Used by&nbsp;Query</A> </LI></UL></LI></UL>
  <LI class=sidebox>
  <H2>Archives</H2>
  <UL>
    <LI><A title="July 2010" href="http://blog.sqlauthority.com/2010/07/">July 
    2010</A> 
    <LI><A title="June 2010" href="http://blog.sqlauthority.com/2010/06/">June 
    2010</A> 
    <LI><A title="May 2010" href="http://blog.sqlauthority.com/2010/05/">May 
    2010</A> 
    <LI><A title="April 2010" href="http://blog.sqlauthority.com/2010/04/">April 
    2010</A> 
    <LI><A title="March 2010" href="http://blog.sqlauthority.com/2010/03/">March 
    2010</A> 
    <LI><A title="February 2010" 
    href="http://blog.sqlauthority.com/2010/02/">February 2010</A> 
    <LI><A title="January 2010" 
    href="http://blog.sqlauthority.com/2010/01/">January 2010</A> 
    <LI><A title="December 2009" 
    href="http://blog.sqlauthority.com/2009/12/">December 2009</A> 
    <LI><A title="November 2009" 
    href="http://blog.sqlauthority.com/2009/11/">November 2009</A> 
    <LI><A title="October 2009" 
    href="http://blog.sqlauthority.com/2009/10/">October 2009</A> 
    <LI><A title="September 2009" 
    href="http://blog.sqlauthority.com/2009/09/">September 2009</A> 
    <LI><A title="August 2009" 
    href="http://blog.sqlauthority.com/2009/08/">August 2009</A> 
    <LI><A title="July 2009" href="http://blog.sqlauthority.com/2009/07/">July 
    2009</A> 
    <LI><A title="June 2009" href="http://blog.sqlauthority.com/2009/06/">June 
    2009</A> 
    <LI><A title="May 2009" href="http://blog.sqlauthority.com/2009/05/">May 
    2009</A> 
    <LI><A title="April 2009" href="http://blog.sqlauthority.com/2009/04/">April 
    2009</A> 
    <LI><A title="March 2009" href="http://blog.sqlauthority.com/2009/03/">March 
    2009</A> 
    <LI><A title="February 2009" 
    href="http://blog.sqlauthority.com/2009/02/">February 2009</A> 
    <LI><A title="January 2009" 
    href="http://blog.sqlauthority.com/2009/01/">January 2009</A> 
    <LI><A title="December 2008" 
    href="http://blog.sqlauthority.com/2008/12/">December 2008</A> 
    <LI><A title="November 2008" 
    href="http://blog.sqlauthority.com/2008/11/">November 2008</A> 
    <LI><A title="October 2008" 
    href="http://blog.sqlauthority.com/2008/10/">October 2008</A> 
    <LI><A title="September 2008" 
    href="http://blog.sqlauthority.com/2008/09/">September 2008</A> 
    <LI><A title="August 2008" 
    href="http://blog.sqlauthority.com/2008/08/">August 2008</A> 
    <LI><A title="July 2008" href="http://blog.sqlauthority.com/2008/07/">July 
    2008</A> 
    <LI><A title="June 2008" href="http://blog.sqlauthority.com/2008/06/">June 
    2008</A> 
    <LI><A title="May 2008" href="http://blog.sqlauthority.com/2008/05/">May 
    2008</A> 
    <LI><A title="April 2008" href="http://blog.sqlauthority.com/2008/04/">April 
    2008</A> 
    <LI><A title="March 2008" href="http://blog.sqlauthority.com/2008/03/">March 
    2008</A> 
    <LI><A title="February 2008" 
    href="http://blog.sqlauthority.com/2008/02/">February 2008</A> 
    <LI><A title="January 2008" 
    href="http://blog.sqlauthority.com/2008/01/">January 2008</A> 
    <LI><A title="December 2007" 
    href="http://blog.sqlauthority.com/2007/12/">December 2007</A> 
    <LI><A title="November 2007" 
    href="http://blog.sqlauthority.com/2007/11/">November 2007</A> 
    <LI><A title="October 2007" 
    href="http://blog.sqlauthority.com/2007/10/">October 2007</A> 
    <LI><A title="September 2007" 
    href="http://blog.sqlauthority.com/2007/09/">September 2007</A> 
    <LI><A title="August 2007" 
    href="http://blog.sqlauthority.com/2007/08/">August 2007</A> 
    <LI><A title="July 2007" href="http://blog.sqlauthority.com/2007/07/">July 
    2007</A> 
    <LI><A title="June 2007" href="http://blog.sqlauthority.com/2007/06/">June 
    2007</A> 
    <LI><A title="May 2007" href="http://blog.sqlauthority.com/2007/05/">May 
    2007</A> 
    <LI><A title="April 2007" href="http://blog.sqlauthority.com/2007/04/">April 
    2007</A> 
    <LI><A title="March 2007" href="http://blog.sqlauthority.com/2007/03/">March 
    2007</A> 
    <LI><A title="February 2007" 
    href="http://blog.sqlauthority.com/2007/02/">February 2007</A> 
    <LI><A title="January 2007" 
    href="http://blog.sqlauthority.com/2007/01/">January 2007</A> 
    <LI><A title="December 2006" 
    href="http://blog.sqlauthority.com/2006/12/">December 2006</A> 
    <LI><A title="November 2006" 
    href="http://blog.sqlauthority.com/2006/11/">November 2006</A> </LI></UL>
  <LI class=sidebox>
  <DIV class=textwidget><A 
  href="http://s37.sitemeter.com/stats.asp?site=s37sqlauthority"><IMG 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/meter.gif"></A> 
  <A href="http://www.copyscape.com/"><IMG height=31 
  alt="Page copy protected against web site content infringement by Copyscape" 
  src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/cs-wh-3d-88x31.gif" 
  width=88 border=0></A></DIV></LI></UL></DIV><!-- end id:sidebar --></DIV><!-- end id:content --></DIV><!-- end id:container -->
<DIV id=footer>
<P><A href="http://wordpress.com/" rel=generator>Blog at WordPress.com</A>.</P>
<P>Theme: Mistylook by <A href="http://wpthemes.info/" 
rel=designer>Sadish</A>.</P><BR class=clear></DIV><!-- end id:footer -->
<SCRIPT type=text/javascript>_qoptions={qacct:'p-18-mFEk4J448M',labels:'language.en,viplite.sqlauthority'};</SCRIPT>

<SCRIPT 
src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/quant.js" 
type=text/javascript></SCRIPT>
<NOSCRIPT>
<P><IMG class=robots-nocontent style="DISPLAY: none" height=1 alt="" 
src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/p-18-mFEk4J448M.gif" 
width=1></P></NOSCRIPT>
<SCRIPT 
src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/beacon.js" 
type=text/javascript></SCRIPT>

<SCRIPT 
type=text/javascript>try{COMSCORE.beacon({c1:2,c2:7518284});}catch(e){}</SCRIPT>
<NOSCRIPT>
<P class=robots-nocontent><IMG style="DISPLAY: none" height=1 alt="" 
src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/p.gif" 
width=1></P></NOSCRIPT>
<SCRIPT 
src="SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record « Journey to SQL Authority with Pinal Dave_files/w.js" 
type=text/javascript></SCRIPT>

<SCRIPT type=text/javascript>
st_go({'blog':'668536','v':'wpcom','user_id':'0','post':'43','subd':'sqlauthority'});
ex_go({'crypt':'RDZ8LFkxbXF0aVJhPVYmfFFiVHRaT3c1VXJETkJ+LTc0LyxWcEo4RGhuQmFNUH5dZGFTLSxWZmllam56bStnck5dRUJ8P3p8eFd8aXVLV25aJW51VGh6b1YyV3Z2di5wdjZiUkssX0JULTdTW1tFNGprd3E4MVs4bTZIPz9yc1Y5W2didlNzRlFzVnBoVi1oSCZ3TXM2LEFbSFtZNHR2alRbd1RxMUorMW4sRHlJXy1ddnlsMVdsa2NCOWIxOV1zVHQsPXczbWguYTVXREt4Y0I4MVNCb2UmST8yS1tid3lnLUp1a2dDYTB2bV16RlQrQV8tN11qMzVEcTFCdlNMTmMxZWQ='});
addLoadEvent(function(){linktracker_init('668536',43);});
	</SCRIPT>
</BODY></HTML>
